admin管理员组文章数量:1293067
Top page:
...
<script>
if (window.addEventListener) {
// addEventListener equivalent of code below
} else if (window.attachEvent) {
window.attachEvent("message", function(e) {
if (e.origin != "page2.html") { return; }
alert(e.data);
});
}
</script>
<iframe src="page2.html"></iframe>
page2.html:
<script>
var message = "hello!";
parent.postMessage(message, '*');
</script>
This code works fine in Chrome, Firefox and Opera. Of course IE has its own way of doing things so this code doesn't work despite using its own .attachEvent
.
The page2.html is actually a page on another domain; I'm sending the correct P3P headers (shouldn't matter, but there's that).
How do I find out why postMessage
doesn't seem to be reaching the parent page?
Top page:
...
<script>
if (window.addEventListener) {
// addEventListener equivalent of code below
} else if (window.attachEvent) {
window.attachEvent("message", function(e) {
if (e.origin != "page2.html") { return; }
alert(e.data);
});
}
</script>
<iframe src="page2.html"></iframe>
page2.html:
<script>
var message = "hello!";
parent.postMessage(message, '*');
</script>
This code works fine in Chrome, Firefox and Opera. Of course IE has its own way of doing things so this code doesn't work despite using its own .attachEvent
.
The page2.html is actually a page on another domain; I'm sending the correct P3P headers (shouldn't matter, but there's that).
How do I find out why postMessage
doesn't seem to be reaching the parent page?
1 Answer
Reset to default 11attachEvent
takes its event name in the form "onmessage"
, as opposed to addEventListener
(which uses "message"
)
本文标签: javascriptwindowattachEvent doesn39t seem to be working in IE8Stack Overflow
版权声明:本文标题:javascript - window.attachEvent doesn't seem to be working in IE8 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741569652a2385929.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论