0

I am working on a phonegap build project and I need to open all external links on the default browser.

I've tried this setting:

<preference name="stay-in-webview" value="false" />

but that's not opening the link in the default browser.

How can I get all external links to open in the default browser?

4

1 回答 1

2

如果我没记错的话,你需要使用org.apache.cordova.inappbrowser挂钩window.open函数的插件,并添加新的_system目标(这会打开默认的网络浏览器)。

所以你可以强制你的链接window.open像这样使用(jQuery):

$('a').click(function() {
    if (this.host !== window.location.host) {
        window.open(this.href, '_system');
        return false;
    }
});
<a href="http://stackoverflow.com">Stackoverflow</a>
于 2016-06-12T21:38:52.303 回答