2016-01-14 143 views
0

我在我管理的网站中发布了一些错误报告,并且每过一段时间我都会收到Uncaught SecurityError: Blocked a frame with origin "https://domain.com" from accessing a cross-origin frame的错误报告。在堆栈跟踪中的行号后面,我看到它是我访问document.querySelector("iframe#results-map").contentWindow的地方。然而,这个iframe是通过一个相对URL访问的:/html/googleresultsmap.html,所以它不能是跨源的(实际上它工作的时间是99.9%,因为我没有这样的许多报告)。所有报告都报告Chrome(各种版本/变体)。同源请求被阻止为跨源

那么一个相对URL如何导致一个跨源帧?

<iframe src="/html/googleresultsmap.html" id="results-map"></iframe>

document.querySelector("iframe#results-map").contentWindow

回答

0

我发现这是当document.domain明确设置某个地方的情况。如果您尝试使用Safari开发人员工具,则发现它在此情况下更有帮助,其中包含以下消息:

Blocked a frame with origin "{accessor}" from accessing a frame with origin "{accessee}". The frame requesting access set "document.domain" to "blah.com", but the frame being accessed did not. Both must set "document.domain" to the same value to allow access. 
+0

我没有设置“document.domain”。它可能在哪里设置?也许浏览器扩展?我将如何解决它? – Jayen

+0

您是否尝试过使用Safari开发工具,它提供了更彻底的错误消息吗? –

+0

我无法复制它。这不是在我的机器上发生的。它似乎只占用户机器的0.1%。 – Jayen

相关问题