关于javascript:未捕获的SecurityError:无法从“ HTMLIFrameElement”读取“ contentDocument”属性

Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement'

我正在尝试根据特定需要创建自己的"网站检查器",并且在访问iFrame时遇到问题。

Uncaught SecurityError: Failed to read the 'contentDocument' property
from 'HTMLIFrameElement': Blocked a frame with origin"http://
checker.xcore.co.il" from accessing a frame with origin"http://
xcore.co.il". The frame requesting access set"document.domain" to
"checker.xcore.co.il", but the frame being accessed did not. Both must
set"document.domain" to the same value to allow access.

我必须使用iFrame进行此操作,因为我需要访问CSS类。
单击此链接,加载网站,然后单击右侧的" fontSizeErrors"
然后您可以在控制台日志中看到错误。

我怎样才能通过这个? 我在Google上找不到任何有用的信息。

谢谢!


这是所有浏览器使用的正常安全措施。 您无法访问起源不同的元素或框架,这将是一个巨大的安全漏洞。 因此,浏览器将阻止所有尝试执行此类操作的脚本。 要在框架内执行任何操作,其内容必须具有相同的来源。

有关更多信息,请查看我的答案。