Search code examples
javascriptdom-events

Event variable set even if not in parameters


Given the following code:

openUserProfile: function(){
    event.preventDefault();

    // Rest of function
}

In Firefox, it throws ReferenceError: event is not defined as expected, because event is not passed in as a parameter. However in Chrome and Safari, event is defined and thus the code above runs fine.

Is there an explanation for this?


Solution

  • Go through this thread; window.event is not defined in FF

    Javascript Error in FireFox Not in IE and Chrome

    Instead try this:-

    openUserProfile: function(e){
        e.preventDefault();
    
        // Rest of function
    }