Javascript 未捕获的安全错误:无法从“HTMLIFrameElement”读取“contentDocument”属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26329519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 22:43:56  来源:igfitidea点击:

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

javascriptjqueryiframe

提问by Neit

i'm trying to make my own "website checker" for specific needs and i'm having problem accessing the iFrame..

我正在尝试针对特定需求制作自己的“网站检查器”,但在访问 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.

未捕获的安全错误:无法从“HTMLIFrameElement”读取“contentDocument”属性:阻止了来源为“http://checker.xcore.co.il”的框架访问来源为“http://xcore.co.il”的框架”。请求访问的框架将“document.domain”设置为“checker.xcore.co.il”,但被访问的框架没有。两者都必须将“document.domain”设置为相同的值以允许访问。

I must do this using iFrame because i need to access classes CSS. Click on this link, load the website and then click "fontSizeErrors" on the right and then you can see the error in the console log.

我必须使用 iFrame 来做到这一点,因为我需要访问 CSS 类。 单击此链接,加载网站,然后单击右侧的“fontSizeErrors”,然后您可以在控制台日志中看到错误。

How can i pass this please?? I couldn't find anything helpful on Google..

请问这个怎么通过??我在谷歌上找不到任何有用的东西..

Thanks!

谢谢!

回答by Marco Bonelli

That's a normal security measure used by all the browsers. You can'taccess elements or frames that have a different origin, that would be a huge security flaw. Hence, the browser blocks all the scripts that try to do that kind of stuff. To perform any action inside a frame its content must have the same origin.

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

For further information take look at this answerof mine.

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