简体   繁体   English

未捕获的SecurityError:无法从“ HTMLIFrameElement”读取“ contentDocument”属性:阻止了框架

[英]Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame

I want to add JavaScript links to any site urls with iframe. 我想使用iframe将JavaScript链接添加到任何网站网址。 But it returns error like this. 但是它会返回这样的错误。

"Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame" “未捕获的SecurityError:无法从'HTMLIFrameElement'读取'contentDocument'属性:阻止了一个框架”

I tried it with javascript. 我尝试使用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);

I think there will be solution with php. 我认为会有php解决方案。 Is there any? 有没有?

The Same Origin Policy prevents you from touching other domains. 相同来源策略可防止您接触其他域。 Heck sites can even block you from sticking your page in an iframe. Heck网站甚至可以阻止您将页面粘贴在iframe中。

PHP is not going to do anything unless you are going to scrap the content, rewrite all of the URLs and output it on your server. PHP不会做任何事情,除非您要剪贴内容,重写所有URL并将其输出到服务器上。 Doing this is a BAD idea because if someone finds out you are doing it, they can add a script to your page that does some awesome things to it. 这样做是一个不好的主意,因为如果有人发现您正在执行此操作,他们可以将脚本添加到您的页面中,以执行一些令人敬畏的事情。

This can be down to several factors, but generally speaking this will be due to security settings preventing you from writing into and out of the iFrame. 这可以归结为几个因素,但通常来说,这是由于安全设置导致您无法写入和注销iFrame。 There are numerous settings which prevent this in your browser, which can be disabled if you so wish, however if this is functionality that you wish to provide to other page visitors, it will likely involve them changing browser security settings to implement, and is a very bad route to follow - I would recommend finding an alternative solution. 有许多设置可以防止您的浏览器出现这种情况,如果您愿意,可以将其禁用,但是,如果您希望将此功能提供给其他页面访问者,则可能会涉及到他们更改浏览器的安全性设置以实施。遵循的非常糟糕的路线-我建议您找到替代解决方案。

More information: What you can and can't do with iFrames 详细信息: 使用iFrame可以做什么和不能做什么

Please don't use iframe. 请不要使用iframe。 Please use html dom parser instead iframe. 请使用html dom解析器代替iframe。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Uncaught SecurityError:无法从'HTMLIFrameElement'读取'contentDocument'属性:阻止了一个源为“https:// localhost”的帧 - Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin “https://localhost” Uncaught SecurityError:无法从'HTMLIFrameElement'读取'contentDocument'属性 - Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement' SecurityError:无法从“ HTMLIFrameElement”读取“ contentDocument”属性 - SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement Uncaught SecurityError:无法读取'contentDocument'属性 - Uncaught SecurityError: Failed to read the 'contentDocument' property 未捕获到的SecurityError:阻止了具有原点的框架…无法访问具有原点的框架 - Uncaught SecurityError: Blocked a frame with origin … from accessing a frame with origin 未捕获的DOMException:无法读取“ contentDocument” - Uncaught DOMException: Failed to read the 'contentDocument' 方法未捕获的SecurityError:阻止了具有原点的框架 - Method Uncaught SecurityError: Blocked a frame with origin “未捕获的安全错误:无法从‘文档’读取‘cookie’属性:Cookies 在‘数据:’URL 中被禁用。” Flutter webview - “Uncaught SecurityError: Failed to read the 'cookie' property from 'Document': Cookies are disabled inside 'data:' URLs.” Flutter webview 未捕获的SecurityError:阻止具有原点“null”的帧访问具有原点“null”的帧。 协议,域和端口必须匹配 - Uncaught SecurityError: Blocked a frame with origin “null” from accessing a frame with origin “null”. Protocols, domains, and ports must match 如何避免未捕获的SecurityError:使用phonegap阻止源为原始的帧 - How to avoid Uncaught SecurityError: Blocked a frame with origin with phonegap
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM