简体   繁体   English

Iframe中的IE9窗口对象没有addEventListener

[英]IE9 window object inside an Iframe has no addEventListener

I'm adding an Iframe to a page by using javascripts document.write. 我通过使用javascripts document.write将iframe添加到页面。 The page (from another domain) that is called inside the Iframe does a bit of setup using 在iframe中调用的页面(来自另一个域)使用

window.addEventListener('load', function() { 
    //do stuff here 
}

It works in Chrome. 它适用于Chrome。 It works in Firefox. 它可以在Firefox中使用。 It works in Opera. 它可以在Opera中工作。

It doesn't work in IE9. 在IE9中不起作用。 I get the strangest message, that "the Object does not have the property or method 'addEventListener'". 我收到最奇怪的消息,即“对象不具有属性或方法'addEventListener'”。 It's apparently the window object IE9 is talking about, because when I 显然是IE9在谈论窗口对象,因为当我

console.log(window)

i get 我得到

[object Window]

but when I 但是当我

console.log(window.addEventListener)

I get 我懂了

undefined

When I call the page directly the script works fine, but in the Iframe I get this magical castrated window object that does not know addEventListener (and probably other stuff too)?! 当我直接调用页面时,脚本可以正常工作,但是在iframe中,我得到了这个神奇的cast割窗口对象,该对象不知道addEventListener(可能还包括其他东西)? What the hell is happening here? 这到底是怎么回事?

After much trial and error I found out that the page that was creating my Iframe had broken HTML (no Doctype, no title tag) and thus forced IE9 into Quirks mode, which apparently means reduced abilities. 经过多次试验和错误,我发现正在创建Iframe的页面损坏了HTML(没有Doctype,没有标题标签),因此迫使IE9进入Quirks模式,这显然意味着功能降低。 After cleaning up the loading page it works fine. 清理完加载页面后,它可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM