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?

Satch3000
  • 47,356
  • 86
  • 216
  • 346

1 Answers1

2

If I remember correct, you need to use the plugin org.apache.cordova.inappbrowser which hooks the window.open function, and adds the new _system target (this opens the default web browser).

So you can force your links to use window.open like this (jQuery):

$('a').click(function() {
    if (this.host !== window.location.host) {
        window.open(this.href, '_system');
        return false;
    }
});
<a href="http://stackoverflow.com">Stackoverflow</a>
Midas
  • 7,012
  • 5
  • 34
  • 52