Event or window.event

var obj = document.getElementById('link');
obj.attachEvent('onclick',handler);
function handler(event){
     alert(window.event === event);                    //false
}

I don’t know why the result is false not true.So what the event in the funciton presents?

Hi 110qunide, welcome to the forum

try

.....
alert(typeof window.event); 
alert(typeof event); 
..... 

What to you get?

window.event is for IE, the event parameter is according to the standards, hence that only would be true if the browser supports both (IE 9?).

All of the result is object

yes, I used IE 10 ,but the result is still false

How about loosely typed?

alert(window.event == event); // only 2 = signs

the result has not changed

stab in the dark

var e = window.event || e;
var targ = e.target || e.srcElement;

used this for ie/safari compatibility…dunno if it’ll help!

me too.
what you write is right.And thanks.But I want to know why the result (event === window.event) is false.
I mean they all grobal variable values in IE 10. event is equal to a attributes of window

They are pointing to two different event objects.

window.event is the IE event object while the one passed as a parameter when the function is called is the JavaScript event object (which is NOT in global scope and therefore can never be equal to one that is).

In JavaScript two objects are only equal when they are the exact same object and not two different but identical objects.

Using window.event is now obsolete as all versions of IE from 9 onward now support JavaScript.

Great thanks!
I am a little known.And can you give me an example to explain it exactly when they are to be equalized.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.