Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获安全性错误:无法读取';内容文档';来自'的属性;HtmlFrameElement';:用“原点”阻止帧;https://localhost"_Javascript_Securityexception - Fatal编程技术网

Javascript 未捕获安全性错误:无法读取';内容文档';来自'的属性;HtmlFrameElement';:用“原点”阻止帧;https://localhost"

Javascript 未捕获安全性错误:无法读取';内容文档';来自'的属性;HtmlFrameElement';:用“原点”阻止帧;https://localhost",javascript,securityexception,Javascript,Securityexception,我在试图捕获G+follow按钮的点击事件时遇到了以下问题 未捕获的SecurityError:未能从“HTMLIFrameElement”读取“contentDocument”属性:阻止源代码为“”的帧访问源代码为“”的帧。协议、域和端口必须匹配。我发现了类似的讨论 当您尝试将ajax调用到另一个域时会引发此问题,请查看本文以了解有关同源策略的更多信息 要修复此问题,您需要添加此代码 从文章本身来看: 页面可能会更改其自身的来源,但有一些限制。脚本可以将document.domain的值设置

我在试图捕获G+follow按钮的点击事件时遇到了以下问题


未捕获的SecurityError:未能从“HTMLIFrameElement”读取“contentDocument”属性:阻止源代码为“”的帧访问源代码为“”的帧。协议、域和端口必须匹配。

我发现了类似的讨论

当您尝试将ajax调用到另一个域时会引发此问题,请查看本文以了解有关同源策略的更多信息

要修复此问题,您需要添加此代码

从文章本身来看:

页面可能会更改其自身的来源,但有一些限制。脚本可以将document.domain的值设置为当前域的子集。如果这样做,则较短的域将用于后续原点检查。例如,假设文档中的一个脚本执行以下语句:

执行该语句后,该页将通过原始检查。但是,基于同样的理由,company.com无法将document.domain设置为othercompany.com

端口号由浏览器单独保存。对setter的任何调用,包括document.domain=document.domain,都会导致端口号被null覆盖。因此,仅在第一个字段中设置document.domain=“company.com”,无法使company.com:8080与company.com对话。必须在这两个字段中都设置,以便端口号都为空


我的解决方案重建了iframe,并在角度上可用。 当我们构建iframe时,需要进行源安全检查来修改iframe内容。此解决方案允许我们多次重新创建iframe内容

HTML

JS
var content=“Iframe内的内容”//iframe的所需内容
var iframecontainer=document.getElementById(“iframecontainer”);
iframecontainer.innerHTML='';
var iframe=iframecontainer.childNodes[0];
让doc=iframe.contentDocument | | iframe.contentWindow;
doc.open();
文件编写(内容);
doc.close();

可能重复或我尝试了您的解决方案,但我收到消息:SecurityError:未能在“文档”上设置“域”属性:“”不是“localhost”的后缀。
document.domain = 'yourdomain.com'
document.domain = "company.com";
<div id="iframecontainer"></div>
var content = "<h1>Content inside Iframe</h1>"; //desired content of iframe
var iframecontainer = document.getElementById("iframecontainer");
iframecontainer.innerHTML ='<iframe id="threedsframe" width="%90" height="400px"></iframe>';
var iframe = iframecontainer.childNodes[0];
let doc =  iframe.contentDocument || iframe.contentWindow;
doc.open();
doc.write(content);
doc.close();