javascript - 防止 iframe 中的恶意 Flash 广告将用户重定向到顶部位置

标签 javascript flash iframe

我的网站布局如下:

{主页 (包含 Flash 广告的 iframe) }

有时,恶意 Flash 广告会加载到框架中并将用户重定向到他们选择的网站。我想他们在 ActionScript 中使用 getURL() 函数。

由于我拥有首页以及框架内的页面,因此我能够编辑两者的 html,因此无论如何都可以阻止 Flash 广告通过 iframe 发送请求来更改顶部位置。

如有任何帮助,我们将不胜感激。 谢谢。

最佳答案

HTML5 来拯救!

只需将其添加到您的 iframe:

sandbox="allow-scripts"

此 iframe 沙箱功能可防止 iframe 中的任何内容重定向页面或执行任何顶部框架导航。

您想要的一个值是:

allow-scripts - Allows script execution

您不想要的其他三个沙箱选项是:

allow-same-origin - Allows the iframe content to be treated as being from the same origin as the containing document
allow-forms - Allows form submission
allow-top-navigation - Allows the iframe content to navigate (load) content from the containing document

完全“沙盒”iframe:

sandbox=""

功能齐全的 iframe:

sandbox="allow-scripts allow-forms allow-same-origin allow-top-navigation"

(或直接省略该属性)

关于javascript - 防止 iframe 中的恶意 Flash 广告将用户重定向到顶部位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10197806/

相关文章:

javascript - 是否可以使用 JavaScript 从 Flash applet 拖放至外部?

flash - 在 IE9 Beta 中可以使用 Flash ExternalInterface 吗?

javascript - 在 iframe 中搜索代码

javascript - 同一个源 iframe 的 Express.js : get req. body.datas

css - 如何使 ReactPlayer 随高度和宽度缩放

javascript - 理解javascript中的setInterval

javascript - 全页导航幻灯片淡入淡出问题

javascript - Outlook Web 插件显示错误消息作为信息

javascript - 如何将日期从下拉列表转换为 javascript 日期格式并增加 1 天?

flash - Youtube API 函数