Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript check if a variable is the window

do you know a good way to check if a variable is the window object in javascript? I tried with:

var variable=window;
Object.prototype.toString.call(variable);

In Firefox it returns "[object Window]" but in IE "[object Object]" so that's not the right way. Do you know an accurate way to check it?

like image 964
mck89 Avatar asked Jun 23 '10 07:06

mck89


1 Answers

Found this in AngularJS source code. A one liner and bang on target.

return variable && variable.document && variable.location && variable.alert && variable.setInterval;
like image 70
RAJCHOW Avatar answered Sep 17 '22 04:09

RAJCHOW