Sorcy
Sorcy

Reputation: 2613

IE9 window object inside an Iframe has no addEventListener

I'm adding an Iframe to a page by using javascripts document.write. The page (from another domain) that is called inside the Iframe does a bit of setup using

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

It works in Chrome. It works in Firefox. It works in Opera.

It doesn't work in IE9. I get the strangest message, that "the Object does not have the property or method 'addEventListener'". It's apparently the window object IE9 is talking about, because when I

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)?! What the hell is happening here?

Upvotes: 2

Views: 950

Answers (1)

Sorcy
Sorcy

Reputation: 2613

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. After cleaning up the loading page it works fine.

Upvotes: 3

Related Questions