Will
Will

Reputation: 63

phonegap jquerymobile : how to open external links via Android Browser

I am working on a project with PhoneGap and JqueryMobile in Android. Now I need to open an external link via the Android Browser. I just write

window.location.href("http://stackoverflow.com")

or

window.open("http://stackoverflow.com")

The App didn't reply at all? Please tell me why and help me out. Thanks.

Upvotes: 3

Views: 5276

Answers (3)

Matto
Matto

Reputation: 118

Use this

window.open('http://www.myurl.nl', '_blank', 'location=yes');

Upvotes: 0

Miskah
Miskah

Reputation: 11

Comment in phonegap config "res/xml/config.xml"

<access origin=".*" browserOnly="true"/>

by

<!--<access origin="*" browserOnly="true"/>-->

If you allow access, you allow website to be viewed in webview (in this case ALL website). With no access, all external link are open in native browser.

Upvotes: 1

codemonkey
codemonkey

Reputation: 5267

You need to use navigator.app.loadUrl('http://stackoverflow.com');

EDIT Some code for PhoneGap always needs to be device-specific. What I do rather than device check is load a "platform" JS file which has code for each feature that has platform-specific code.

So you can create a function called openUrl which you define in each (Android, iOS, etc) project. In your index.html you just load the platform.js file using a relative path. The implementation can then be platform-specific without ugly device checking.

Upvotes: 8

Related Questions