Opening the System browser from your PhoneGap app.

  • 1
  • Idea
  • Updated 5 years ago
An FYI as requested, this successfully opened the link in Safari and Chrome on iOS and Android, respectively:

html/javscrtipt code:

<a href="#" class="topcoat-button" onclick="window.open('http://yahoo.com', '_system', 'location=yes');">System Browser</a>

config.xml (latest PG version):

<preference name="phonegap-version" value="cli-5.1.1" />
<gap:plugin name="cordova-plugin-inappbrowser" source="npm" />

config.xml (older):
<preference name="phonegap-version" value="3.7.0" />
<gap:plugin name="org.apache.cordova.inappbrowser" source="plugins.cordova.io" />

Edit wrong javascript code
Photo of ryan

ryan, Developer

  • 1538 Posts
  • 132 Reply Likes

Posted 5 years ago

  • 1
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Two remarks, if I may:

1. in the onclick attribute, it would be a good idea to cancel the default href action. This can be done by adding return false;

2. the plugin uses cordova.InAppBrowser.open() instead of window.open(). Until the next major release, it will also hook window.open(), but only for a limited time and for backwards compatibility. It would be better to use the cordova.InAppBrowser.open() function when writing new apps.
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
Petra, thanks for the note. I'll make sure to make note of it.
Photo of ryan

ryan, Developer

  • 1538 Posts
  • 132 Reply Likes
Thanks!
Photo of ryan

ryan, Developer

  • 1538 Posts
  • 132 Reply Likes
@PierreRose -- you're not including cordova.js in your index.html file. No PhoneGap / Cordova functionality will work without this.

<script src="cordova.js"></script>