javascript - 未捕获的安全错误 : Failed to read the 'contentDocument' property

标签 javascript http https

我在我的网站上有 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/

相关文章:

objective-c - iOS 5 : https ( ASIHTTPRequest) stop working

c++ - 无法使用 C++、Qt 和 Betfair API-NG 使用 SSL 证书登录

javascript - 如何重构函数以在间隔停止时返回 promise ?

javascript - 在 JavaScript 中设置代理

http - 我应该什么时候响应我网站上的 HTTP HEAD 请求

rest - 基于 token 的 REST API 身份验证

regex - 将 http 重定向到 https OS X Server 5.0.15

javascript - Angular Radio ng-change 仅在第一次时有效

javascript - 如何将小时转换为天小时和分钟?

javascript - 如何在浏览器控制台中使用单行代码多次执行javascript命令?