safari vs. firefox on javascript window.event

tench

Registered
i don't know what i'm going wrong -- my code works in safari, but not in firefox. i was wondering if someobdy could help me track down the problem.

i have a function which ought to split normal clicks from alt-clicks.. and process them differently. fine.

so i have something like

Code:
<a onclick="check()">click me</a>
and a corresponding function

Code:
function check(evt) {
evt = (evt) ? evt : ((window.event) ? window.event : "")
if (evt) {
if (evt.altKey) {
//blah-blah
} else {
//blah-blah
}
}
}
now this works just fine in safari, but in firefox window.event is always undefined. i.e. even if i do a simple function which does alert(window.event), it's undefined.

what's wrong with firefox and window events or what's wrong with me for using them?

all best,
tench
 

Nummi_G4

New Rhapsody User
tench, my understanding is that window.event is an Internet Explorer thing. Also, isn't there an issue with alt click, shift clicks, ctrl clicks, etc being used for certain functions like opening the clicked link in a new tab?

The W3C standard for getting access to an event is 'e'.
The Microsoft way is window.event.

A nice way to get it all on the same name would be to do this:
Code:
function theFunction(e) { 
if (!e) var e = window.event; 
// do something useful
}
 
Top