<script>alert (Object.prototype.toString.call (window)) </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
The result is a multitude of:
[Object] IE6
[Object] IE8
[Object window]firefox3.6
[Object window]opera10
[Object domwindow]safai4.04
[Object global]chrome5.0.3.22
Look at the famous how to determine, it is determined whether there is a property called SetInterval. Gee, it seems not too rigorous, but also can not be rigorous, because in IE can not determine whether the function of the generalization function, Object.prototype.toString.call all played [object], there is no Name attribute. Because it is too easy to imitate, discard it.
Helpless, check its properties, see what special attributes. Finally found that there is a window property with the same name, it is an infinite loop referencing itself. This is a bit more problematic in IE.
<script>alert (window = = Window.window) </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
IE will eject false and other browsers may eject true. But here's how all browsers are unified:
<script>alert (window = = Window.window) </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Is there a rigorous decision? Do not forget that window is an infinite loop referencing itself, it should be said to refer to the previous self. Therefore, we can:
<script>alert (Window.window = = Window.window.window) </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
The final conclusion:
Copy Code code as follows:
var IsWindow = function (obj) {
return Obj.window = = Obj.window.window
}
====================== Gorgeous line of demarcation =====================
Thank Ivony for the inspiration!
Copy Code code as follows:
function IsWindow (obj) {
if (typeof obj!== "Object") return false;//must be An object
var expando = "dom" + (new Date-0)//Generate a random variable name
//Global parsing code, IE eval only valid for the original scope
//See http://www.javaeye.com/to pic/519098
//plus eval and with is the HTML5 strict mode to prohibit things, discard it!
var js = document.createelement ("script");
var head = document.getElementsByTagName ("head") [0];
Head.insertbefore (Js,head.firstchild);
Js.text = expando + "= {};"
Head.removechild (JS)
return Window[expando] = = Obj[expando]
}
IsWindow (window)