0

So pretty much I have an html that has an iFrame.

<iframe src="frame.html" width="2000" height="1000"></iframe>

Now, from within the iFrame js I try to call jQuery's append function to add a DIV to the parent window...

$("body", window.parent.document).append("<div id=\"test\" ></div>");

That code works perfectly fine under FireFox and IE, but for some reason it doesn't work under Chrome, and I've tried Googling the cause of this with little to no luck.

Just FYI, this was all done under jQuery 2.0.0.

4

1 回答 1

1

我目前正在自己​​的计算机上开发,因此我通过提供路径来访问每个 iframe。

那就是问题所在。使用本地网络服务器并通过http://(或https://)URL 进行测试。如果你稍后通过 URL 测试你想要作为网页的东西file://,你会被误导。

在这种情况下,您对评论的怀疑是正确的: It's Same Origin Policy。不同的浏览器对待源null(本地文件系统)的方式不同。当您的窗口从本地文件加载时,Chrome 不允许访问其他窗口。

于 2013-05-11T09:15:53.487 回答