【问题标题】:Cordova: load links in webviewCordova:在 webview 中加载链接
【发布时间】:2017-03-23 18:43:08
【问题描述】:

我在 iOS 上的 cordova webview 中的 iframe 中加载了一个外部网站(具有不同的 HTML 文件)。

现在,当我单击 iframe 中的普通链接(指向另一个 html 页面)时,Safari 浏览器会打开该页面。但我希望它改变 iframe 内的位置。 它起作用的唯一方法是覆盖点击操作

$('a').click(function(event){
    event.preventDefault();
    window.location.replace($(this).attr('href'));
}

但这并不好。有什么办法可以防止cordova在外部safari应用程序中打开链接(可能在config.xml中)?

【问题讨论】:

    标签: javascript cordova iframe cordova-plugins


    【解决方案1】:

    看看cordova-plugin-whitelist插件:

    https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/

    此插件实现了用于在 Cordova 4.0 上导航应用程序 web 视图的白名单策略

    您可能希望在 config.xml 中添加如下内容:

    <allow-navigation href="http://example.com/*" />
    

    ....对于每个受信任的域,其中 example.com 是受信任的域

    【讨论】:

      【解决方案2】:

      代替 window.location.replace,尝试使用 window.open 并以 _self 作为名称。

      window.open($(this).attr('href'), "_self");
      

      https://cordova.apache.org/docs/en/2.6.0/cordova/inappbrowser/window.open.html

      【讨论】:

      • 它也适用于我发布的脚本,但我不想将脚本添加到 iframe 中的每个 html 页面。我只想说一般“不要在外部 safari 应用程序中打开链接”或在链接中添加一些东西(如 )来阻止它但它不起作用。
      猜你喜欢
      • 1970-01-01
      • 2019-07-30
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      • 2022-07-27
      • 1970-01-01
      • 2021-11-28
      • 1970-01-01
      相关资源
      最近更新 更多