【发布时间】: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