Phonegap - 在Mobile Safari中打开链接

Dav*_*vid 1 html javascript cordova

在我将我的应用程序更新到Cordova 2.5.0之前,我的基本链接已打开到Safari中.现在它只是在我的应用程序视图中加载而不是加载到Safari中.

我有以下代码: Contact Us by visiting, <a href="http://site.com/contact.php"> our website! </a>

关于如何解决这个问题的任何想法.

有关更多信息:这一切都是从我们从Cordova/Phonegap.plist切换到config.xml时开始的.

小智 5

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 ];
    }
}
Run Code Online (Sandbox Code Playgroud)

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);
                          }
Run Code Online (Sandbox Code Playgroud)