通常,当您点击网络浏览器上的“使用Facebook注册”按钮时,将弹出一个新选项卡。但是当你尝试在WebView
上做同样的事情时,它不会做任何事情,它会停留在同一个网站上。如何强制WebView
显示对话框?
答案 0 :(得分:0)
在您的代理中实施-webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:
。如果你还没有,你可能还需要实现至少一些WebUIDelegate协议方法。
参考:WebPolicyDelegate Protocol Reference,WebUIDelegate Protocol Reference
答案 1 :(得分: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!)