在使用PhoneGap的JQuery Mobile中,链接不在外部浏览器中打开 [英] Links don't open in external browser in JQuery Mobile with PhoneGap

查看:184
本文介绍了在使用PhoneGap的JQuery Mobile中,链接不在外部浏览器中打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PhoneGap 2.3.0中使用JQuery Mobile 1.2.0时遇到问题。

I'm having a problem in PhoneGap 2.3.0 with JQuery Mobile 1.2.0.

任何外部链接iniOS在应用程序中打开,

Any external link iniOS opens inside the app instead of opening Safari they open inside the app, making it impossible for user to get back to the app without rebooting it.

我已尝试过 rel =external

我已经看到了PhoneGap的默认方式,它是一个外部链接,但没有成功。

I have seen that the default way that PhoneGap with JQMobile should act is the way I want. I have found lots of requests for this kind of behaviour, but not the way around.

推荐答案

我添加了

I added rel="external" to my anchor links.

然后添加/覆盖 shouldStartLoadWithRequest MainViewController 类中的$ c>方法:

And then added/overrided the shouldStartLoadWithRequest method in the MainViewController class:

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

这在我的jQuery Mobile 1.2和Phonegap 2.2 .0。它应该工作相同在Phonegap 2.3.0 - 但我没有测试。

That works for me in jQuery Mobile 1.2 and Phonegap 2.2.0. It should work the same in Phonegap 2.3.0 - but I haven't tested that.

================ ==================================================== ================

==================================================================================

UPDATE

在Phonegap 2.7.0或更高版本中可能没有任何需要这样做。 Phonegap现在可以在UIWebView,Safari或InAppBrowser组件中打开链接。我个人喜欢InAppBrowser组件,因为它似乎是一个更好的用户体验很多用例。如果你想在Safari中打开链接,现在可以使用Javascript:

There may not be any need to do this in Phonegap 2.7.0 or above. Phonegap can now open links in either of the UIWebView, Safari or the InAppBrowser component. Personally I like the InAppBrowser component, as it seems to be a better user experience for a lot of use cases. If you want to open links in Safari you can now do this now using Javascript:

window.open('http://whitelisted-url.com', '_system');

或InAppBrowser:

or this for the InAppBrowser:

window.open('http://whitelisted-url.com', '_blank');

请在这里查看更多信息:

Have a look here for more information:

http://wiki.apache.org/cordova/InAppBrowser
http://docs.phonegap.com/en/2.7.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser

这篇关于在使用PhoneGap的JQuery Mobile中,链接不在外部浏览器中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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