Beware: Many browsers define window.event

Some browsers define window.event, which will return a copy of the "current" event. However, this is not defined by the W3C. Most importantly, Firefox does not support it, neither do recent versions of IE.

You should completely avoid accessing the global event and instead pass the event object around that the event handler receives. The easiest protection against accidentally accessing window.event is just never naming the event event, but e or evnt or so.

function brokenInFirefox() {
  event.preventDefault(); // Breaks in Firefox
}

function worksInAnyBrowser(event) {
  event.preventDefault(); // Works in most browsers
}

function workaround(e) {
  e.preventDefault(); // Protects against accidentally using window.event
}
Dominik Schöler Over 8 years ago