javascript - Phonegap - 在 Mobile Safari 中打开链接

标签 javascript html cordova

在我将我的应用程序更新到 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/

相关文章:

android - 任务 ':app:processArm64DebugResources'的执行失败。 >无法执行Aapt

javascript - Vue JS : How can I access and change Css root variables from vue component to toggle CSS Variables Site Theming?

javascript - Bacon.js:使用鼠标选择、拖放以及使用箭头键触摸和移动

javascript - jQuery 包含来自输​​入文本

javascript - 选择时更改标签的颜色

html - 使用 CSS 动画属性对类更改进行多个 CSS 转换

html - CSS Nth of Type 未定位

javascript - Hello World phonegap 应用程序崩溃

ios - Ionic 3 不正确的滚动行为

javascript - 如何使用函数而不发生冲突