window.event alternative in Firefox

This is the typical approach that you’ll find in examples everywhere.

document.onmouseover = function(event) {
    event = event || window.event;

    var mouseX = event.clientX;
    var mouseY = event.clientY;
}

The W3C standard way of retrieving the event object is via the first function parameter. Older IE didn’t support that approach, so event will be undefined. The || operator lets us fetch the window.event object in that case.

Leave a Comment