链接无法在Safari或InAppBrowser中打开

时间:2013-05-25 04:51:06

标签: javascript jquery ios cordova

所以我一直在这里寻找并找到了大量的答案,但大部分都是在有plist的情况下是2.3科尔多瓦。然后我找到了一些使用新的config.xml设置,但是无法在Safari中打开URL或者这里的InAppBrowser是我的代码,我列出的白色也列有*白色。

<a href="http://www.academymusicgroup.com/" onclick="window.open(this.href,'_blank'); return false;">AcademyMusicGroup</a>

1 个答案:

答案 0 :(得分:0)

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);
                          }