简体   繁体   English

在cordova webview中打开外部URL(不是在AppBrowser中)

[英]Open external URL in cordova webview (NOT inAppBrowser)

What I want to do?我想做的事? To open an external URL to open in the internal cordova webview, where the index.html file loads by default.打开外部 URL 以在内部cordova webview 中打开,默认加载index.html 文件。

What do I not want to do and why?我不想做什么,为什么? Use the inAppBrowser, because (1) in android it shows the address bar.使用 inAppBrowser,因为 (1) 在 android 中它显示地址栏。 (2) The external URL of the website is such that people post links there often.. They all open up in the inAppBrowser. (2) 网站的外部 URL 是人们经常在那里发布链接的方式。它们都在 inAppBrowser 中打开。 I would prefer them to open in a different browser in the phone.我希望它们在手机的不同浏览器中打开。

What have I tried so far without success?到目前为止我尝试了什么没有成功?

(1) window.location.href="http://www.example.com"; (1) window.location.href="http://www.example.com";

(2) window.open('http://www.example.com', '_self ', 'location=yes'); (2) window.open('http://www.example.com', '_self ', 'location=yes');

(3) var url = 'http://www.example.com'; var target = '_blank'; var options = "location=yes, toolbar=no"; var ref = cordova.InAppBrowser.open(url, target, options); (3) var url = 'http://www.example.com'; var target = '_blank'; var options = "location=yes, toolbar=no"; var ref = cordova.InAppBrowser.open(url, target, options); var url = 'http://www.example.com'; var target = '_blank'; var options = "location=yes, toolbar=no"; var ref = cordova.InAppBrowser.open(url, target, options);

(4) Use an iframe in index.html <iframe src="http://www.example.com ></iframe> (4)在index.html中使用iframe <iframe src="http://www.example.com ></iframe>

(5) <allow-navigation href="http://*/*" /> <allow-navigation href="https://*/*" /> <allow-navigation href="tel:*" /> <allow-navigation href="sms:*" /> <allow-navigation href="mailto:*" /> <allow-navigation href="geo:*" /> (5) <allow-navigation href="http://*/*" /> <allow-navigation href="https://*/*" /> <allow-navigation href="tel:*" /> <allow-navigation href="sms:*" /> <allow-navigation href="mailto:*" /> <allow-navigation href="geo:*" />

Any leads would be helpful.任何线索都会有所帮助。 Thanks a lot in advance folks!非常感谢大家!

With Apple's new WKWebView requirement, this just got sloppy.随着 Apple 的新 WKWebView 要求,这变得草率了。 None of the whitelisting etc worked for me, nor could I use InAppBrowser.open now window.open with _system target.白名单等都不适合我,我也不能使用 InAppBrowser.open 现在 window.open 和 _system 目标。 I ended up using this plugin and solved.我最终使用了这个插件并解决了。

https://github.com/PaoloMessina/OpenUrlExt https://github.com/PaoloMessina/OpenUrlExt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM