user626963
user626963

Reputation:

How do I pass the event and variable in firefox?

This works in IE, but not Firefox. I understand that window.event does not exist in Firefox, but I can't figure out the correct syntax to make it work.

HTML: <tr onclick="getDETAILS('getTASKS');"

Javascript:

  function getDETAILS(action) {
     if (window.event.ctrlKey) { 
        //doing something with action
     }
  }

Upvotes: 1

Views: 456

Answers (2)

Fabr&#237;cio Matt&#233;
Fabr&#237;cio Matt&#233;

Reputation: 70139

Cross-browser solution:

<tr onclick="getDETAILS('getTASKS', event);">

JS:

function getDETAILS(action, e) {
    e = e || window.event;
    if (e.ctrlKey) {
        alert('do stuff');
    }
}​

Fiddle

The event object will be passed to the function's formal parameter e in all modern browsers.

If the passed event object is undefined (older versions of IE), e is set to window.event.

Upvotes: 1

jsalonen
jsalonen

Reputation: 30481

The following works with IE, Firefox and Chrome. (latest versions)

HTML:

<tr onclick="getDETAILS(event, 'getTASKS');">

JavaScript:

function getDETAILS(evt, action) {
  if(evt.ctrlKey) {
    //doing something with action
  }
}

Live demo: http://jsfiddle.net/vYUS8/2/

Upvotes: 1

Related Questions