14

How do you open links in the devices native browser when using Cordova 3.0 on iOS?

People have suggested using window.open( url, "_system" ) but this does not work in Cordova 3.0.

My Attempt

if( navigator.app ) // Android
    navigator.app.loadUrl( url, {openExternal:true} )
else // iOS and others
    window.open( url, "_system" ) // opens in the app, not in safari

Does anyone know of a solution that works with Cordova 3.0?
Thanks

Splendiferous
  • 733
  • 2
  • 6
  • 17
  • Check my 2015 answer here to open `_self` in WebView, and `_blank` in external browser: http://stackoverflow.com/questions/32208609/cordova-why-would-inappbrowser-plugin-be-required-to-open-links-in-system-brows/32227524 – Sebastien Lorber Aug 26 '15 at 13:38

2 Answers2

20

NOTE: to make window.open('somelink', '_system') to work you now need a device-level plugin, the inAppBrowser. Here are the installing instructions as of Cordova 3.0

From the Docs for 3.0:

As of version 3.0, Cordova implements device-level APIs as plugins. Use the CLI's plugin command, described in The Command-line Interface, to add or remove this feature for a project:

$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
$ cordova plugin rm org.apache.cordova.core.inappbrowser

These commands apply to all targeted platforms, but modify the platform-specific configuration settings described below:

iOS (in config.xml)

<feature name="InAppBrowser">
    <param name="ios-package" value="CDVInAppBrowser" />
</feature>

I just tested this and it works.

Justus Romijn
  • 15,699
  • 5
  • 51
  • 63
dannytenaglias
  • 343
  • 3
  • 6
  • 9
    Worth noting that it appears the InAppBrowser plugin enables handling of `_system` links as well ([http://cordova.apache.org/docs/en/3.1.0/cordova_inappbrowser_inappbrowser.md.html#window.open](http://cordova.apache.org/docs/en/3.1.0/cordova_inappbrowser_inappbrowser.md.html#window.open)) – Justin Russell Oct 09 '13 at 14:27
  • @dannytenaglias go ahead and put that in your answer. Something like: NOTE: to make `window.open('somelink', '_system')` to work you now need a device-level plugin, the inAppBrowser. Here are the installing instructions as of Cordova 3.0: – Justus Romijn May 21 '14 at 13:51
4

install InAppBrowser plugin:

$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
$ cordova plugin rm org.apache.cordova.core.inappbrowser

and execute the plugin in your .js file:

//exec(successCallback, errorCallback, pluginName, pluginMethod, params)
cordova.exec(null, null, "InAppBrowser", "open", [url, "_system"]);
gregmatys
  • 2,151
  • 18
  • 19