通常,当您在网络浏览器上单击“使用 Facebook 注册”按钮时,会弹出一个新选项卡。但是,当您尝试在 a 上做同样的事情时,WebView
它不会做任何事情,它会停留在同一个网站上。我怎样才能强制WebView
显示对话框?
问问题
406 次
2 回答
0
这可能是您正在寻找的。将它放在你的 AppDelegate.m 中,然后所有外部链接将在默认浏览器中打开:
// Habilita links externos abrirem no navegador padrão
- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request
{
// HACK: This is all a hack to get around a bug/misfeature in Tiger's WebKit
// (should be fixed in Leopard). On Javascript window.open, Tiger sends a null
// request here, then sends a loadRequest: to the new WebView, which will
// include a decidePolicyForNavigation (which is where we'll open our
// external window). In Leopard, we should be getting the request here from
// the start, and we should just be able to create a new window.
WebView *newWebView = [[WebView alloc] init];
//[newWebView setUIDelegate:self];
[newWebView setPolicyDelegate:self];
return newWebView;
}
- (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
if( [sender isEqual:myWebView] ) {
[listener use];
}
else {
[[NSWorkspace sharedWorkspace] openURL:[actionInformation objectForKey:WebActionOriginalURLKey]];
[listener ignore];
//[sender release];
}
}
- (void)webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id<WebPolicyDecisionListener>)listener {
[[NSWorkspace sharedWorkspace] openURL:[actionInformation objectForKey:WebActionOriginalURLKey]];
[listener ignore];
}
// -
(sim,eu sou br!)
于 2014-01-19T06:25:45.500 回答
0
-webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:
在您的委托中实施。如果您还没有实现,您可能还需要实现至少一些 WebUIDelegate 协议方法。
于 2012-10-21T16:36:54.067 回答