当我试图捕捉G+ follow按钮的点击事件时,我面临着以下问题。
未捕获SecurityError:未能从‘HTMLIFrameElement’读取'contentDocument‘属性:阻止源为"https://localhost“的帧访问源为"https://apis.google.com”的帧。协议、域和端口必须匹配。
发布于 2017-04-04 03:43:44
我的解决方案重建了iframe并在angular中可用。当我们构建iframe时,它需要源安全检查来修改iframe内容。此解决方案允许我们多次重新创建iframe内容。
HTML
<div id="iframecontainer"></div>
JS
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();
https://stackoverflow.com/questions/28272933
复制相似问题