PDA

View Full Version : Get hold of netscape event object.



Vijay Venkat
Apr 25th, 2007, 12:26 PM
Hi

With IE i can get hold of event object using window.event, is there a similar way to get hold of event object in netscape / Fire Fox?

Or is it necessary to pass the event object from the event handler something like



<a href="http://www.somesite.com" onclick="someFunction(event)" />


Here it can be seen that event object is passed from the onclick handler.

It there a way to avoid getting the event from the even handler? that is beacuse if i have to do that, i will have to change lots of files.

Thanks,
Vijay

liorean
Apr 25th, 2007, 01:41 PM
Netscape (and Opera, Safari, iCab, HotJava and just about every JavaScript enabled browser EXCEPT for Internet Explorer) events and the W3C DOM events pass the event object as the first argument to the event handler. In the case of your example
<a href="http://www.somesite.com" onclick="someFunction(event)" />the event handler looks like this in those browsers:
function anonymous(event){
someFunction(event)
}and like this in ie
function anonymous(){
someFunction(event)
}


In other words, if you use DOM0 events the event object can be reached like this:
elm.onevent=function(evt){
evt=evt||window.event;
someFunction(evt);
}