Phonegap - 在移动Safari中打开链接 [英] Phonegap - Open Link in Mobile Safari

查看:96
本文介绍了Phonegap - 在移动Safari中打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Before I updated my application to Cordova 2.5.0, my basic link opened up into Safari. Now it just loads in my Application view and not into Safari.

我有以下代码:
通过访问联系我们,< a href =http://site.com/ contact.php>
我们的网站! < / a>

有关如何解决这个问题的任何想法。

Any idea on how I can fix this.

有关详细信息:这一切都是从Cordova / Phonegap.plist切换到config.xml时开始的。

For more information: it all started when we switched to config.xml from Cordova/Phonegap.plist.

推荐答案

1)在safari中打开链接

1)open links in safari

将代码粘贴到MainViewController.m文件中

paste the code in your MainViewController.m file

- (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中打开链接

2)open links in 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);
                          }

这篇关于Phonegap - 在移动Safari中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆