Javascript Phonegap-在Mobile Safari中打开链接
在我将应用程序更新到Cordova 2.5.0之前,我的基本链接打开到Safari。现在它只是加载到我的应用程序视图中,而不是加载到Safari中 我有以下代码:Javascript Phonegap-在Mobile Safari中打开链接,javascript,html,cordova,Javascript,Html,Cordova,在我将应用程序更新到Cordova 2.5.0之前,我的基本链接打开到Safari。现在它只是加载到我的应用程序视图中,而不是加载到Safari中 我有以下代码: 通过访问联系我们, 你知道我该怎么解决这个问题吗 更多信息:当我们从Cordova/Phonegap.plist切换到config.xml时,这一切就开始了。我最近一直在努力解决这个问题,并找到了一个至少对我有效的答案。Cordova 2.6和JQuery Mobile <a href="http://yoursite.some
通过访问联系我们,
你知道我该怎么解决这个问题吗
更多信息:当我们从Cordova/Phonegap.plist切换到config.xml时,这一切就开始了。我最近一直在努力解决这个问题,并找到了一个至少对我有效的答案。Cordova 2.6和JQuery Mobile
<a href="http://yoursite.something.com" target="_system"> the external link </a>
相当多的答案让您使用target=“\u blank”。但这只是在他们的网络视图中打开了链接。希望这对你有用,就像对我一样 最近我一直在努力解决这个问题,并找到了一个至少对我有用的答案。Cordova 2.6和JQuery Mobile
<a href="http://yoursite.something.com" target="_system"> the external link </a>
相当多的答案让您使用target=“\u blank”。但这只是在他们的网络视图中打开了链接。希望这对你有用,就像对我一样 您必须使用这个:window.open(“U系统”)
来源于此:您必须使用这个:window.open(“U系统”) 来源如下: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) 在应用浏览器中打开链接
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);
}
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) 在应用浏览器中打开链接
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);
}
希望有帮助 更新前您使用了旧版本的phonegap?phonegap使用webview(webkit)而不能使用safari。是的,当您打开链接(使用http://)时,它会在safari中打开。就像它会跳转应用程序一样。更新之前您使用了旧版本的phonegap吗?phonegap使用webview(webkit)而不能使用safari。是的,当您打开链接(使用http://)时,它会在safari中打开。就像它会跳转应用程序一样。这在最新版本的PhoneGap中对我有效。在iOS模拟器中,没有其他东西对我有效+1我正在构建的特定应用程序的页面上有一个iframe,这也将在safari中打开它。有没有一个简单的修复方法?这在最新版本的PhoneGap中对我很有效。在iOS模拟器中,没有其他东西对我有效+1我正在构建的特定应用程序的页面上有一个iframe,这也将在safari中打开它。有没有简单的解决方法?如果能在StackOverflow上快速解释或总结,我们将不胜感激。如果能在StackOverflow上快速解释或总结,我们将不胜感激。在Phonegap 3.3中,这将在应用程序中打开,而不是在系统浏览器中打开。(测试iOS6/7)(例如)“>这是因为需要先安装InApp浏览器插件。在Phonegap 3.3中,这会在应用程序中打开,而不是在系统浏览器中打开。(测试iOS6/7)(例如)“>这是因为需要先安装InApp浏览器插件。这对我不起作用。我需要使用
onclick=“window.open('http://example.com“,”系统“”
让它工作。这对我不起作用。我需要使用onclick=“window.open('http://example.com“,”系统“,”
使其工作。