未捕获的SecurityError:未能读取'contentDocument'属性来自'HTML
Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame
我想添加JavaScript链接到任何带有iframe的网站URL。但它会返回这样的错误。
"未捕获的SecurityError:未能读取"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会有解决方案。有吗?
同源策略防止您接触其他域。Heck网站甚至可以阻止你将页面粘贴到iframe中。
PHP不会做任何事情,除非您要废弃内容,重写所有URL并将其输出到服务器上。这样做是个坏主意,因为如果有人发现你在这么做,他们可以在你的页面上添加一个脚本,对它做一些很棒的事情。
这可以归结为几个因素,但一般来说,这将是由于安全设置阻止您在iFrame中写入和写入。浏览器中有许多设置可以防止这种情况的发生,如果您愿意,可以禁用这些设置。但是,如果这是您希望向其他页面访问者提供的功能,则可能需要他们更改浏览器安全设置才能实现,这是一条非常糟糕的路线-我建议您找到替代解决方案。
更多信息:iFrames 可以做什么和不能做什么
请不要使用iframe。请使用html-dom解析器,而不是iframe。
相关文章:
- iframe contentDocument and contentWindow is null
- 如何访问 iframe.contentDocument 以在跨源请求后获得响应
- 无法读取属性'contentDocument'为null
- 访问iframe contentDocument属性时出现跨原点框架问题
- SecurityError:未能读取'contentDocument'属性来自'HTMLIFra
- 未捕获的SecurityError:未能读取'contentDocument'属性来自'HTML
- 未捕获的SecurityError:未能读取'contentDocument'属性来自'HTML
- 一个有内容的iFrame怎么可能有一个未定义的contentDocument对象
- iframe.contentDocument在IE8上不起作用
- 从iframe获取html-“;未能读取contentDocument“;错误
- contentDocument 和 contentWindow javascript iframe/frame 访问属性
- 从文件输入中访问.svg文件's contentDocument - Chrome上的跨框架问题
- "访问被拒绝”;在同一域的IE9中的contentDocument上
- SVG嵌入未加载或无法通过contentDocument访问
- contentDocument for an iframe