1

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

4

4 回答 4

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

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);
                          }
于 2013-06-10T11:54:44.553 回答
4
  1. Add target="_blank" to your links. ie:

    <a href="http://www.brandonbrotsky.com/" target="_blank"></a>
    
  2. Make sure access has an origin of * /> in your config.xml (make sure its the one in the root of the app directory, above the www folder. ie:

    <access origin="*" />
    
  3. Add the following code to 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 ];
        }
    } 
    

I made a quick video explaining how to fix this issue:

http://www.youtube.com/watch?v=zqbjXSnAR-Q&feature=c4-overview&list=UUefS6KLvFQVjhmL6hiBq4Sg

Hope it helps!

于 2013-12-07T22:00:23.077 回答
1

你必须使用这个:window.open(' http: //google.com','_system ');

来源在这里:http ://wiki.apache.org/cordova/InAppBrowser

于 2013-04-25T15:01:57.280 回答
1

我最近一直在努力解决这个问题,并想出了一个至少对我有用的答案。Cordova 2.6 和 JQuery Mobile。

<a href="http://yoursite.something.com" target="_system"> the external link </a>

相当多的答案让您使用 target="_blank"。但这只会在他们的 WebView 中打开链接。希望这对你有用,就像对我一样!

于 2013-04-23T15:24:45.940 回答