gpt4 book ai didi

ios - 防止 iframe 中的链接导航/接管 cordova webview,尤其是在 ios 中

转载 作者:太空狗 更新时间:2023-10-29 15:30:08 34 4
gpt4 key购买 nike

我有使用 iframe 显示外部内容的 Cordova 应用程序(在这种情况下是 youtube 嵌入式视频)

当单击 iframe 内的链接(如 youtube Logo )时,整个 webview 将导航到 youtube 网站,而不仅仅是 iframe。 (没有返回的能力,你需要杀死应用程序),我想阻止的行为。

在 android 上,cordova 插件 api 公开了 onOverrideUrlLoading 方法,它应该能够阻止不需要的导航。 (还没有自己测试过)

我在 ios cordova 类和 ios webview api 中都没有找到类似的方法。但我对 ios 不是很熟悉。

我也尝试过(在 android 和 ios 上)iframe 的沙盒属性 https://developer.mozilla.org/en/docs/Web/HTML/Element/iframe#attr-sandbox这适用于防止脚本(不是我需要那个 atm,只是为了检查属性是否在做某事)但不能防止导航(要启用导航你应该添加 allow-top-navigation 而我没有)

最佳答案

使用html5沙盒属性,同时不允许 allow-top-navigation & allow-popups

<iframe sandbox="allow-scripts allow-same-origin"...

测试:ios 8/7.1,android 4.4

在我之前的检查中,我已将允许弹出窗口添加到沙箱值

<iframe sandbox="allow-scripts allow-same-origin allow-popups"...

关于ios - 防止 iframe 中的链接导航/接管 cordova webview,尤其是在 ios 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26933233/

34 4 0
文章推荐: html - 如何强制所有
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com