cordova – How to make phonegap window.location.href not launch Chrome on Android-ThrowExceptions

Exception or error:

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.

How to solve:

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.

###

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.

Leave a Reply

Your email address will not be published. Required fields are marked *