gpt4 book ai didi

javascript - 取消 iframe 中具有目标 ="_parent"属性的链接事件

转载 作者:行者123 更新时间:2023-11-28 02:46:03 28 4
gpt4 key购买 nike

我有一个 iframe,它显示另一个域上的网站,其中包含具有 target="_parent" 属性的链接。因此,它不会在 iframe 中加载链接,而是重定向整个页面。有没有办法捕获此事件,取消它,并使用 jQuery 或直接使用 javascript 将 iframe 的 url 设置为该链接?

最佳答案

对于支持它的浏览器,您最好使用 sandbox-attribute :

<iframe sandbox="allow-forms allow-scripts allow-same-origin"></iframe>

现在不允许 iframe 更改顶部位置,除非您在属性中列出“allow-top-navigation”

但是链接在 iframe 中不起作用,而是根本不起作用,并且在控制台中记录了安全错误:

http://jsfiddle.net/rRT6S/3/

关于javascript - 取消 iframe 中具有目标 ="_parent"属性的链接事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11851218/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com