为了允许 Vimeo 视频嵌入,我设置了“OpenAllWhitelistURLsInWebView”=“yes”。但自从我这样做以来,它只打开白名单项目并显然在 WebView 中打开它们。我需要在 safari 浏览器中打开所有非白名单项目,而不是 webview。关于如何实现这一目标有什么想法吗?
Cordova 1.7 | XCode 4.3.2 | jQuery 1.7.1 | JqueryMobile 1.1.0 | ios 5.1
最佳答案
我不知道与 Cordovoa 的确切区别,但我正在使用 PG 1.4.1,并且我的 PhoneGap.plist 中有此设置
这在我的AppDelegate.m
中- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
if([[url absoluteString] rangeOfString:@"vimeo.com"].length > 0 || [[url scheme] isEqualToString:@"file"]){
return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
}
[[UIApplication sharedApplication] openURL:url];
return NO;
}
这是我由PG打开的非常简单的index.html
<body>
<a href="http://www.vimeo.com">Vimeo</a>
<a href="http://www.google.com">Google</a>
</body>
vimeo 链接在 WebView 中打开,google 链接在 Safari 中打开。
更新 Cordova 1.7
显然,最新版本的 PhoneGap/Cordova 中没有调用 shouldSTartLoadWithRequest 函数(我认为是从 1.6.1 开始)。因此,现在如果您想在 Safari 中打开链接,则需要将 a 标签的 target
属性设置为 _blank
。由于您并不总是能够访问代码,因此这里有一个脚本可以提供帮助。
<head>
<script type="text/javascript" src="cordova-1.7.0.js"></script>
<script>
document.onclick = checkLink;
function checkLink(e) {
var url = e.target.href;
if(url.indexOf('vimeo.com') == -1){
window.open(url,'_blank');
}
}
</script>
</head>
<body>
<a href="http://www.vimeo.com">Vimeo</a>
<a href="http://www.google.com" target="_blank">Google</a>
</body>
关于ios - 在WebView中打开所有白名单URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10838598/