【问题标题】:Cordova InAppBrowser.open. Links are opening on safari instead of opening inside the appCordova InAppBrowser.open。链接在 Safari 上打开,而不是在应用程序内打开
【发布时间】:2026-01-30 20:35:01
【问题描述】:

我的小 Cordova 应用程序非常简单,在检查是否存在连接后,打开网站的 url(例如http://www.example.com)。 我希望所有的网址/网站都显示在应用程序中。

主要问题是在 iOS 上只打开应用程序的第一页,而任何其他被点击/触摸的链接都会在 safari 浏览器中打开。

在 config.xml 中 我已经设置了

<access origin="*" />

在我添加的 index.js 中

  onDeviceReady: function() {
        window.open = cordova.InAppBrowser.open;
        if (navigator.connection.type == Connection.NONE) {
      navigator.notification.alert('An internet connection is required to continue');
      } else {
          setTimeout(function(){window.open('http://www.example.com', '_self', 'location=no')} , 3000);

      }
    },

我已经尝试在没有 inappbrowser 的情况下使用我的代码(没有前面代码中的第二行并且没有插件)。 我已经删除并阅读了平台。 我重新创建了整个应用程序。 我检查了应用程序(cordova 平台检查)。

在 anrdoid 和 blackberry 上,它可以根据我的需要在应用内导航(带和不带 inappbrowser)工作!

科尔多瓦 6.1.1 mac mini - osx el capitan 10.11.5

【问题讨论】:

    标签: android ios cordova inappbrowser


    【解决方案1】:

    我认为这是由于未正确设置 config.xml 中的 allow-intent href 属性造成的,如下所述:

    https://issues.apache.org/jira/browse/CB-10859

    在您的 config.xml 文件中查找此声明:

    &lt;allow-intent href="*" /&gt;

    并将其替换为更具体的意图允许,例如:

    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    

    这应该涵盖大多数意图。

    【讨论】:

    • 我在意图中添加了特定的网站/网址并添加了更多权限。从 scracth 重建项目并从旧项目复制文件后的所有内容。在投入了一些时间之后,它就起作用了:)。谢谢
    • 您好,我也遇到了同样的问题。你介意分享你改变了什么吗?也许从您的 config.xml 发布部分。非常感谢!
    • @RaziSyed 我在上面发布的内容正是我的配置文件中的内容。