Event Objects

This issue was fixed in Internet Explorer 9.

When a script detects an event, it needs some way to give the event handler the information about the event. What position the mouse was at, what button or key was pressed, what element detected the event, etc. That sort of thing. Well, long ago, Netscape decided the easiest way to do this was to pass an object as a parameter to the event handler function. Internet Explorer used a global variable. Both ways worked, and each had its own weaknesses.

With the Netscape model, the event object has to be passed to each function in turn for them to be able to access the information. With the Internet Explorer model, you risk conflicts if two functions both think they are accessing their own information but due to the order that functions are called, one of them ends up accessing the other function's information from the global variable.

When writing the standard, it was decided that the Netscape model was better (especially since Netscape originally invented the language, and Microsoft deliberately did not implement it properly, as part of their browser wars plans), so that is the correct way to do it. But despite the standards being many years older than the current Internet Explorer versions, IE still does not support it. Why? Because they have decided that since their way works for them, they will not implement the standard correctly.

So scripts have to check if the browser supports the standard, and if not, use the IE event object. Unfortunately, many do not get this correct, and it is the standards compliant browsers that usually suffer. Something so easy for Microsoft to implement (all it takes is to pass the object to the function - the object already exists, it wouldn't be difficult), but just one more thing that they have decided not to do.

Oh and that is before we get on to all of the properties that have incorrect names, such as 'srcElement' instead of 'target', 'from/toElement' instead of 'relatedTarget', and even the missing 'currentTarget'. When an event property already exists, but with the wrong name, it would be so little work to simply make a new property with the correct name, and make it a pointer to the old one. And it would then help to prevent all those badly written event handlers which fail to allow for both models. But I guess we will have to keep waiting.

Demo: This link can detect clicks and should be able to obtain information about the click event.

Workaround: Scripts should use:
function eventHandler(e) {
  if( !e ) { e = window.event; }

'e' should now reference the event object, even if it was not correctly passed to the function.

Don't click this link unless you want to be banned from our site.