【问题标题】:open site in iFrame which avoids Frame Busting在 iFrame 中打开站点,避免 Frame Busting
【发布时间】:2013-01-06 23:54:43
【问题描述】:

我正在尝试在 iFrame 中打开一些以弹出窗口形式打开的网站。 有些网站不允许自己在 iFrame 中打开(Frame Busting)。

我已经搜索过了。我也有一些解决方案,比如

$(window).bind('beforeunload', function (event) {

        return 'Custom message.';
        });

beforeunload 对我不起作用,因为即使在我的网站内导航时它也会运行

我也试过了

 // Event handler to catch execution of the busting script.
        window.onbeforeunload = function () { prevent_bust++ };

        // Continuously monitor whether busting script has fired.
        setInterval(function () {
        if (prevent_bust > 0) {  // Yes: it has fired. 
        prevent_bust -= 2;     // Avoid further action.
        // Get a 'No Content' status which keeps us on the same page.

        window.top.location.href = 'http://mysiteurl/#';
        }
        }, 1);

上面也不起作用,它会重定向到正在 iFrame 中打开的 url。

那么有什么解决方案可以在 IFrame 中打开网站(具有 Frame Buster)。

问候, 萨加尔·乔希

【问题讨论】:

    标签: iframe popup framebusting


    【解决方案1】:

    对于 IE,在你的框架中使用这个 security="restricted"

    <iframe id="frame_id" name="frame_name" security="restricted" src="page.html">  
    </iframe>
    

    编辑:我遇到了同样的问题,但我需要在我的框架中运行脚本等,因此安全限制不好。尝试使用 sandbox="..."

    • allow-forms 允许提交表单
    • allow-popups 允许弹出窗口
    • allow-pointer-lock 允许指针锁定
    • allow-same-origin 允许文档保持其来源
    • allow-scripts 允许 JavaScript 执行,也允许特性自动触发
    • allow-top-navigation 允许文档通过导航顶级窗口来跳出框架

    顶部导航是您想要阻止的,因此将其排除在外,这样就不会被允许。任何遗漏的内容都会被屏蔽

    例如。

            <iframe sandbox="allow-same-origin allow-scripts allow-popups allow-forms" src="http://www.example.com"</iframe>
    

    【讨论】:

      猜你喜欢
      • 2015-05-29
      • 1970-01-01
      • 1970-01-01
      • 2014-04-22
      • 1970-01-01
      • 2014-02-11
      • 2011-11-27
      • 2021-05-14
      • 1970-01-01
      相关资源
      最近更新 更多