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

匿名 (未验证) 提交于 2019-12-03 08:33:39

问题:

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.

回答1:

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.



回答2:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!