可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.