使用Cordova / jQuery-mobile在外部设备浏览器中打开链接 [英] Opening links in external device browser with Cordova/jQuery-mobile

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

问题描述

我在应用程式中有一堆连结。我向他们添加了 rel ='external'target ='_ blank'

I have a bunch of links in my app. I added rel='external' target='_blank' to all of them.

在Ripple仿真器中,或者在常规的桌面浏览器中,这样做效果很好。但在我的Android(JB 4.2.2),它打开在同一个窗口中的链接。点击返回让我回到应用程序,但一切都被拧,应用程序不按计划工作(脚本事件不反应),直到物理重新加载。

In the Ripple emulator, or in a regular desktop browser, this works great. But on my Android (JB 4.2.2) it opens the link in the same window. Hitting "back" takes me back to the app, but everything is screwed and the app does not work as planned (script events do not react), until physically reloaded.

如何确保在设备的浏览器中打开链接?我需要使用Cordova插件吗?

How do I ensure that a link opens in the device's browser? Do I need to use a Cordova plugin?

(我使用Cordova 2.9.0,jQuery 1.10.1,jQuery Mobile 1.3.1)

(I'm using Cordova 2.9.0, jQuery 1.10.1, jQuery Mobile 1.3.1)

推荐答案

在最近几个版本中,这与Cordova / PhoneGap真的很不一样,我相信因为 InAppBrowser 工作,这可能是您的解决方案。

This has been really fickle with Cordova/PhoneGap in the last few releases, I believe because of the InAppBrowser work which might be a solution for you.

我们在外部浏览器中启动的是:

What is working for us to launch in the external browser is:

window.open("http://myurl.com", '_system');

在我们的例子中,我们想要找到所有外部链接,并在Safari / Chrome中启动它们内部链接在我们的Angular路由器)。这可能不是最优雅的解决方案,但是我们现在正在通过捕获链接上的输入事件并接管这样的行为,这样做:

In our case, we want to find all external links and launch them in Safari/Chrome (and keep internal links in our Angular router). This probably isn't the most elegant solution, but we are doing this right now by capturing input events on the links and taking over the behavior like so:

        $(document).on('mousedown','a', function(e) {
            e.preventDefault();
            var elem = $(this);
            var url = elem.attr('href');
            if (url.indexOf('http://') !== -1) {
                window.open(url, '_system');
            }
        });

我希望能帮助你一点。

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

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