【问题标题】:iframe document write to self "Unsafe JavaScript attempt to access frame with URL"iframe 文档写入自我“不安全的 JavaScript 尝试使用 URL 访问框架”
【发布时间】:2012-07-06 08:41:41
【问题描述】:

我在 Chrome 中遇到跨域错误。在 iframe 内的页面上使用 javascript 在其自身内部写入数据。我本身并没有违反任何跨域规则。我相信我看到了错误,因为我在 iframe 的页面中使用了 document.write()document.getElementById(),这导致浏览器认为我正在引用父文档。


parent.html 位于domainA.com

<iframe src="iframe.html"></iframe>


iframe.html 位于domainB.com

<html>
    <head>
        <title>iFrame</title>
    </head>
    <body>
        <script type="text/javascript">
            document.write('hello world');
        </script>
    </body>
</html>

我还应该注意,我尝试过self.document.write() 无济于事。我这里有什么遗漏吗?

【问题讨论】:

  • 所以这只发生在 chrome 中?你在 iframe 中尝试过 window.document.write 吗?
  • 尝试了几乎所有我能想到的 DOM 路径。 window.document.writeself.document.write..纳达
  • 我应该注意到似乎没有什么问题,只是将错误吐出。内容实际上已写入 iframe 文档。

标签: javascript iframe cross-domain


【解决方案1】:

由于没有任何问题并且它只发生在 chrome 中,我认为这可能是一个已知的调试器问题,可能会导致这种情况。看看这个帖子Debugging iframes with Chrome developer tools

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 2011-05-18
    相关资源
    最近更新 更多