【问题标题】:Cordova Wrapper App Where Internal Links Load In App, External Links Load In BrowserCordova Wrapper 应用程序,其中内部链接在应用程序中加载,外部链接在浏览器中加载
【发布时间】:2016-09-04 18:57:54
【问题描述】:

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

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

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

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

<content src="http://example.com/" />
<access origin="*" />
<allow-navigation href="*" />

如果我用allow-intent 定义config.xml,那么内部和外部链接就会在系统浏览器中打开。

<content src="http://example.com/" />
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />

Otherssuggested 使用自定义 javascript 将 target 覆盖为 _system,但是由于我没有自己的观点,所以我不能这样做。

是否可以为cordova-plugin-whitelist 定义allow-intent,以包含所有非内部域的 URL

或者我需要以某种方式覆盖MainViewController 中的shouldStartLoadWithRequest,然后调用[[UIApplication sharedApplication] openURL:url]

【问题讨论】:

    标签: javascript android ios cordova ionic-framework


    【解决方案1】:

    好的,经过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://*/*" />
    

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

    注意,我添加了&lt;allow-navigation href="https://*.facebook.com/*" /&gt; 以允许加载 Facebook 库,否则我收到错误消息。

    ERROR Internal navigation rejected - 
    <allow-navigation> not set for url='https://staticxx.facebook.com/connect/xd_arbiter.php?
    

    还包括&lt;allow-navigation href="about:*" /&gt; 以避免about:blank 出错。

    ERROR Internal navigation rejected - <allow-navigation> not set for url='about:blank'
    

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

    【讨论】:

    • 你是如何做到这一点的?一些 abc.example.com 可以在 webview 中导航,而 xyz.example.com 可以在外部浏览器中导航!
    猜你喜欢
    • 2018-05-31
    • 2018-07-06
    • 2022-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 2016-07-05
    • 2014-09-02
    相关资源
    最近更新 更多