Mick
Mick

Reputation: 2898

Send a variable along with mouse event to a function

I am trying to detect a ctrl + click on a link and then to send a variable to a js function . I have stripped the code down so I can show it as an example below. I find I can detect the ctrl+click event no problem.

<script language="JavaScript">

function mouseDown(e) {
    var ctrlPressed=0;

    var evt = navigator.appName=="Netscape" ? e:event;

   
    ctrlPressed =evt.ctrlKey;
    self.status="" +"ctrlKey=" +ctrlPressed 

    if (ctrlPressed) 
        alert ("Mouse clicked with Ctrl")

    return true;
}

document.onmousedown = mouseDown ;

//-->
</script>

`

But want I now want to do is send a variable to my function i.e.

document.onmousedown = mouseDown("variable")

I appreciate that I am assigning the mouse event to the whole document but in reality this would be a link. (This code is only used in Chrome browsers)

If anyone can give me some pointers that would be really helpful

Upvotes: 3

Views: 1687

Answers (1)

Travis Gockel
Travis Gockel

Reputation: 27703

document.onmousedown = function(e) { mouseDown(e, "variable"); }

Upvotes: 4

Related Questions