Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova 3.0 - Open link in external browser in iOS

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

like image 394
Splendiferous Avatar asked Jul 31 '13 13:07

Splendiferous


People also ask

How to open the link in external browser in Cordova?

If you want to open the link in external browser, you need to do some special arrangements. First of all, you need to install Cordova InAppBrowser. Go to your Cordova project folder and type: With the InAppBrowser you can normally open the URL in-app, which is the default behavior of the plugin, as the name describes.

How to open the device’s default browser in Cordova?

Go to your Cordova project folder and type: With the InAppBrowser you can normally open the URL in-app, which is the default behavior of the plugin, as the name describes. However, to open the URL to the device’s default browser, you can simply use _system as a target.

What is the InAppBrowser window in Cordova?

The InAppBrowser window behaves like a standard web browser, and can't access Cordova APIs. For this reason, the InAppBrowser is recommended if you need to load third-party (untrusted) content, instead of loading that into the main Cordova webview.

How to open the device’s default browser using InAppBrowser?

First of all, you need to install Cordova InAppBrowser. Go to your Cordova project folder and type: With the InAppBrowser you can normally open the URL in-app, which is the default behavior of the plugin, as the name describes. However, to open the URL to the device’s default browser, you can simply use _system as a target.


2 Answers

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.

like image 71
dannytenaglias Avatar answered Nov 13 '22 18:11

dannytenaglias


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"]);
like image 43
gregmatys Avatar answered Nov 13 '22 17:11

gregmatys