views:

82

answers:

1

Hi 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 ie 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

thanks

+1  A: 
document.onmousedown = function(e) { mouseDown(e, "variable"); }
Travis Gockel
don't you still need the event 'e'?
Sanjay Manohar
Thanks for trying , but this does not detect the mouse click now ?
Mick
oh yes you are right, so - document.onmousedown=function(e){mouseDown(e,"variable");}
Sanjay Manohar
That did it ! , thanks very much
Mick