I'm trying to understand why the following is not working as I would think it does. I'd like to check whether an object is a window. I was thinking that checking the constructors of the current window and another window would work.
So, first creating another window:
var popup = window.open('', '', '');
And then checking with:
popup.constructor === window.constructor;
But for some reason the results vary among browsers:
- IE7: Returns
true
- But that's simply because
.constructor === undefined
- But that's simply because
- IE8: Returns
false
- IE9: Throws an error with no text (
""
) - Chrome: Returns
false
- Though in both cases
.constructor === DOMWindow
- butDOMWindow
is not accessible directly like this
- Though in both cases
- Opera: Returns
false
- Though in both cases
.constructor === Object
- Though in both cases
- Firefox: Returns
false
- Though in both cases
.constructor === Window
- Though in both cases
Why isn't this reliable and working correctly? jQuery simply checks for "setInterval" in window
, but I'd like to create a more robust function for checking whether an object is a window.