我在我的网站上有 facebook 之类的插件,我尝试通过代码获取 facebook iframe 的内容:
iframe[0].contentDocument || iframe[0].contentWindow.document;
但在控制台中我得到这个错误:
Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://like2see.co.il" from accessing a frame with origin "https://www.facebook.com". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "https". Protocols must match
我进行了搜索,得到了这个答案 Console displays Uncaught SecurityError所以我明白,因为我的网站不是 https,那里有一个解决方案,但我不理解他,也许有人知道另一种解决方案,或者可以向我解释那里提到的那个?
最佳答案
除非您禁用浏览器的安全功能,否则您将无法跨域查看 Facebook.com 上 iframe 的内容。
在 Google Chrome 中,您可以使用这些启动标志禁用安全性,但不推荐:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-running-insecure-content --disable-web-security
此外,您的用户不会禁用他们的安全性。
您需要找到另一种方法来完成您正在尝试做的事情。
这other answer关于同源策略可能有助于阅读。
关于javascript - 未捕获的安全错误 : Failed to read the 'contentDocument' property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33176807/