Cordova Wrapper应用程序内部链接在应用程序中加载,外部链接在浏览器中加载

Dal*_*Zak 11 javascript android ios cordova ionic-framework

我有一个简单的Cordova包装应用程序,它指向外部网页,而不定义任何自己的视图.

我希望来自该域的所有内部链接都加载到应用程序内,但所有外部链接(http://twitter.com等)都要加载到系统浏览器中,因此这些页面具有后退/前进功能.

在具有视图的普通应用程序中,我可以设置target='_system'在默认浏览器中加载链接,或使用cordova-plugin-inappbrowser在Web浏览器视图中显式打开链接.不幸的是,在这种情况下,我无法编辑服务器端代码,因此需要一个适用于应用程序的解决方案.

如果我这样定义config.xml,那么内部和外部链接都会加载到app中.

<content src="http://example.com/" />
<access origin="*" />
<allow-navigation href="*" />
Run Code Online (Sandbox Code Playgroud)

如果我定义了config.xmlwith allow-intent,则在系统浏览器中打开内部和外部链接.

<content src="http://example.com/" />
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
Run Code Online (Sandbox Code Playgroud)

其他建议使用自定义javascript来覆盖targetto _system,但是因为我没有自己的观点,所以我不能真正做到这一点.

是否可以定义allow-intent科尔多瓦-插件白名单以这样的方式,包括不属于内部域的所有URL

或将我需要以某种方式覆盖shouldStartLoadWithRequestMainViewController,然后调用[[UIApplication sharedApplication] openURL:url]

Dal*_*Zak 8

好的,经过Hayyaan的一些实验和建议,我能够想出组合allow-navigationallow-intent实现我的目的.

<content src="https://example.com/" />
<access origin="*" />
<allow-navigation href="about:*" />
<allow-navigation href="https://example.com/*" />
<allow-navigation href="https://*.example.com/*" />
<allow-navigation href="https://*.facebook.com/*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
Run Code Online (Sandbox Code Playgroud)

现在,来自网站域的所有内部链接都加载到应用程序中,而外部链接则加载到系统浏览器中.

注意,我包括<allow-navigation href="https://*.facebook.com/*" />允许加载Facebook库,否则我收到错误.

ERROR Internal navigation rejected - 
<allow-navigation> not set for url='https://staticxx.facebook.com/connect/xd_arbiter.php?
Run Code Online (Sandbox Code Playgroud)

并且还包括<allow-navigation href="about:*" />以避免错误about:blank.

ERROR Internal navigation rejected - <allow-navigation> not set for url='about:blank'
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助其他人有同样的问题:)