开发者

How to reference DOMWindow type in Google Chrome?

开发者 https://www.devze.com 2023-02-05 21:19 出处:网络
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 consol

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号