在我将我的应用程序更新到 Cordova 2.5.0 之前,我的基本链接打开到 Safari。现在它只是加载到我的应用程序 View 中,而不是加载到 Safari 中。
我有以下代码:
Contact Us by visiting, <a href="http://site.com/contact.php">
our website! </a>
关于如何解决这个问题的任何想法。
有关更多信息:当我们从 Cordova/Phonegap.plist 切换到 config.xml 时,一切都开始了。
最佳答案
1)在safari中打开链接
将代码粘贴到您的 MainViewController.m 文件中
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
// Intercept the external http requests and forward to Safari.app
// Otherwise forward to the PhoneGap WebView
if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}
else {
return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
}
}
2)在InAppBrowser中打开链接
function OpenLink()
{
alert(adlink); //adlink: http://www.google.com
var ref = window.open(adlink, '_blank', 'location=yes');//adlink is url
var myCallback = function() { alert(event.url); }
ref.addEventListener('loadstart', myCallback);
ref.removeEventListener('loadstart', myCallback);
}
关于javascript - Phonegap - 在 Mobile Safari 中打开链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15349630/