Javascript check if a variable is the window
Found this in AngularJS source code. A one liner and bang on target.
return variable && variable.document && variable.location && variable.alert && variable.setInterval;
Yes but i need a way to check every window not only the current one
There are a few ways you can do this. The simplest method is to check for one or two known properties on the window object. There's also the self
property - for each window, you could check the self
property is equal to the window object:
myvar.self == myvar;
window.self == window;
frameElement.contentWindow.self == frameElement.contentWindow;