【问题标题】:Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame未捕获的安全错误:无法从“HTMLIFrameElement”读取“contentDocument”属性:阻止了一个框架
【发布时间】:2015-12-09 15:14:49
【问题描述】:

我想使用 iframe 将 JavaScript 链接添加到任何网站的 url。 但它会返回这样的错误。

“未捕获的安全错误:无法读取 'contentDocument' 属性 来自“HTMLIFrameElement”:阻止了一个框架”

我用 javascript 试过了。

    $('iframe').contents().find('head').append(created_script);
        created_script=document.createElement('script');
    created_script.src='http://tag-test-super-star.c9users.io/server/js/index.js';
    created_script.type='text/javascript';
    $('.iframe_tag').contents().find('head').append(created_script);

我认为 php 会有解决方案。有吗?

【问题讨论】:

标签: javascript php html


【解决方案1】:

Same Origin Policy 可防止您接触其他域。哎呀网站甚至可以 block you 将您的页面粘贴在 iframe 中。

除非您要废弃内容、重写所有 URL 并将其输出到您的服务器上,否则 PHP 不会做任何事情。这样做是个坏主意,因为如果有人发现您正在这样做,他们可以向您的页面添加一个脚本,对它执行一些真棒 的事情。

【讨论】:

    【解决方案2】:

    这可能归结为几个因素,但一般来说,这是由于安全设置阻止您写入和写入 iFrame。在您的浏览器中有许多设置可以防止这种情况发生,如果您愿意,可以将其禁用,但是如果这是您希望向其他页面访问者提供的功能,则可能需要他们更改浏览器安全设置以实现,并且是非常糟糕的路线 - 我建议寻找替代解决方案。

    更多信息:What you can and can't do with iFrames

    【讨论】:

      【解决方案3】:

      请不要使用 iframe。 请使用 html dom 解析器代替 iframe。

      【讨论】:

        猜你喜欢
        • 2014-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-10
        • 2017-07-08
        • 2017-07-27
        • 1970-01-01
        • 2015-04-04
        相关资源
        最近更新 更多