How do I check if a variable is of type DOMWindow in Google Chrome? When I try referencing the DOMWindow type, I get a ReferenceError. For example, when I try checking the type of window in the console:
> window instanceof DOMWindow
ReferenceError: DOMWindow is not defined
But window is cle开发者_开发知识库arly of type DOMWindow. What am I doing wrong?
What am I doing wrong?
You get a reference error ReferenceError: DOMWindow is not defined
because there is no DOMWindow
member on the global object to check against.
You get the same error if you type window instanceof rubbish
window.constructor.name
may give you what you want (a string "DOMWindow" to check against), althogh I should warn you that it's non-standard.
Try using .constructor
. Example:
alert(window.constructor);
That should give DOMWindow or some variation thereof, at least in Chrome.
精彩评论