]
The results are varied:
[object Object]IE6
[object Object]IE8
[object Window]firefox3.6
[object Window]opera10
[object DOMWindow]safai4. 04
[object global]chrome5.0.3.22
Look at how Heheming determines it and determine whether it has a property called setInterval. Gee, it doesn’t seem too rigorous, but it can’t be more rigorous, because it is impossible to determine whether a generalized function is a function in IE. Object.prototype.toString.call always prints [object Object], and there is no name attribute. Because it was too easy to copy, it was discarded.
In desperation, check its attributes one by one to see if there are any special attributes. I finally discovered that there is a window property with the same name, which refers to itself in an infinite loop. This is still a problem in IE.
If you need to introduce external Js, you need to refresh to execute
]
[Ctrl A Select all Note:
if necessary External Js needs to be refreshed to execute
]
[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh it. Execute
Copy the code
The code is as follows:
var isWindow = function(obj){
return obj.window === obj.window.window
}
Copy code
The code is 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 is only valid for the original scope
//See http://www.javaeye.com/topic/519098 for details
//In addition, eval and with are prohibited in HTML5 strict mode, so discard them!
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] <script>alert(Object.prototype.toString.call(window))</script>} <script>alert(window === window.window)</script>isWindow(window) <script>alert(window == window.window)</script><script>alert(window.window === window.window.window)</script>