The name says a lot about everything. I need to check if the object is an instance of the DOM: Window interface. windowthe test will pass window.frames[xyz]if an iframe exists.
The most intuitive way is to simply check through object instanceof window.constructor. It is sad that there are browsers (e.g. IE6) whose window.constructorequal undefined.
What would you suggest? There are always hacker, ugly, and toStringaddictive ways, such as /\[object.*window.*\]/i.test(object), but I would rather go for a simple, clean solution, if possible.
source
share