Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make phonegap window.location.href not launch Chrome on Android

Tags:

I've got a phonegap app. On deviceReady I set window.location.href to some other URL. This works great on iOS 8.3 but on Android 5.0.1 I get asked if I want to open it in Chrome and then it's opened in Chrome instead of my app.

Is there way to get the URL to open in the app (as in replace the current page). Yes I know that's not best practice, a one page app is better, blah blah blah but that doesn't fit my use case at the moment.

like image 506
gman Avatar asked May 10 '15 12:05

gman


2 Answers

If you are using cordova 5 (or above) with the android platform 4.0.0 (or above), have a look at: https://github.com/apache/cordova-plugin-whitelist

install the plugin via:

cordova plugin add https://github.com/apache/cordova-plugin-whitelist.git --save

in your config.xml you need to add:

<allow-navigation href="https://example.com/*" />

thanks to that, you will allow the webview to load your page.

like image 72
dbaq Avatar answered Sep 18 '22 11:09

dbaq


try

document.location=url;

if this doesn't work, install inAppBrowser plugin and use this

window.open(url,"_self");

and of course inside device ready function.

like image 20
AtanuCSE Avatar answered Sep 21 '22 11:09

AtanuCSE