0

How to open a URL in default browser in android?

I've tried <a href="#" onclick="window.open('http://www.google.com', '_system');">www.google.com</a> but it opens up in the same app window, but I want it to open up in a default browser's window.

Temp O'rary
  • 5,366
  • 13
  • 49
  • 109
  • 1
    for me it is open my default browser only..i just copy paste your above code.. – Aravin Sep 16 '14 at 05:30
  • 1
    check this http://stackoverflow.com/questions/15534630/phonegap-build-how-to-open-external-url-in-device-browser-on-android – Aravin Sep 16 '14 at 05:46
  • oh is it! Which device are you using? ... I have tested this in Nexus 4 and the AVD or android emulator and this is what happens. – Temp O'rary Sep 16 '14 at 06:02
  • nexus 7 and also emulator. May be if you are using phonegap build you got like above... – Aravin Sep 16 '14 at 06:03
  • Oh now I got what I missed :) ... I had missed to add `` in my plugin.xml. Thanks for sharing the link @Aravin. :) If you can post it as an answer I can mark this as answered – Temp O'rary Sep 16 '14 at 06:09

2 Answers2

2

Make sure you added the in app browser plugin. Please check it in your config.xml file(It is in your res/xml/config.xml) the following line is present.

<plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser" />

Like the following you can add the plugin:

phonegap local plugin add your plugin url here

And also chances may be there if you are using phonegap build the in app browser is open instead of default system browser(even though you are using _system).

For more details refer this Stack overflow answer

Community
  • 1
  • 1
Aravin
  • 4,126
  • 1
  • 23
  • 39
  • 1
    Thanks, I am using AngularJS and PhoneGap to make this app but the click does not open up the web page not even inside the app or in the default web browser. But when i use this without angularjs it works. any idea why this might be happening? – Temp O'rary Sep 19 '14 at 05:48
  • 1
    Thats OK Aravin. Anyways your solution worked for the normal HTML, JS, Phonegap solution :) – Temp O'rary Sep 19 '14 at 06:26
-1

You need to install inappbrowser plugin in your app like this

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

after successful install the above code will start working.

Adarsh Nahar
  • 319
  • 3
  • 10