我有一个简单的Cordova https://cordova.apache.org/包装器应用程序指向外部网页,而不定义任何自己的视图。
我想来自该域的所有内部链接都将加载到应用程序内, but 所有外部链接(http://twitter.com http://twitter.com等)在系统浏览器中加载,因此页面具有后退/前进功能。
在具有视图的普通应用程序中,我可以设置target='_system'
在默认浏览器中加载链接,或使用Cordova-插件-inappbrowser https://www.npmjs.com/package/cordova-plugin-inappbrowser在 Web 浏览器视图中显式打开链接。不幸的是,在这种情况下,我无法编辑服务器端代码,因此需要一个在应用程序内工作的解决方案。
如果我定义config.xml
因此,内部和外部链接都会加载到应用程序中。
<content src="http://example.com/" />
<access origin="*" />
<allow-navigation href="*" />
如果我定义config.xml
with allow-intent
,然后在系统浏览器中打开内部和外部链接。
<content src="http://example.com/" />
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
Others https://stackoverflow.com/a/29430835/385730 have 建议 http://weblog.west-wind.com/posts/2015/Jul/02/External-Links-in-Cordova-for-iOS#HandlingTargetLinks使用自定义 javascript 来覆盖target
to _system
,但是由于我没有自己的观点,所以我不能真正这样做。
是否可以定义allow-intent
为了科尔多瓦插件白名单 https://github.com/apache/cordova-plugin-whitelist以这样的方式包括所有非内部域的 URL?
或者我需要以某种方式覆盖shouldStartLoadWithRequest
in MainViewController
然后打电话[[UIApplication sharedApplication] openURL:url]
?