首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >未捕获元素:无法从‘https://localhost“SecurityError’读取'contentDocument‘属性:阻止了原始地址为”HTMLIFrameElement“的帧

未捕获元素:无法从‘https://localhost“SecurityError’读取'contentDocument‘属性:阻止了原始地址为”HTMLIFrameElement“的帧
EN

Stack Overflow用户
提问于 2015-02-02 15:30:35
回答 1查看 57.5K关注 0票数 20

当我试图捕捉G+ follow按钮的点击事件时,我面临着以下问题。

未捕获SecurityError:未能从‘HTMLIFrameElement’读取'contentDocument‘属性:阻止源为"https://localhost“的帧访问源为"https://apis.google.com”的帧。协议、域和端口必须匹配。

EN

回答 1

Stack Overflow用户

发布于 2017-04-04 03:43:44

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

HTML

代码语言:javascript
复制
<div id="iframecontainer"></div>

JS

代码语言:javascript
复制
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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28272933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档