Control+click action in javascript.
10
Gives you control to perform actions when the control key and the mouse button is clicked in the same time. Something similar to selecting elements in Windows with ctrl+click.
Just change the event.ctrlKey to event.shiftKey to make it shift+click. If you don't get it don't worry the snippet contains the demo for shift+click too.
You may need to change the event.which though 1 = left click, 2 = middle click, 3 = right click(at least in firefox 1.5.0.5)
Just change the event.ctrlKey to event.shiftKey to make it shift+click. If you don't get it don't worry the snippet contains the demo for shift+click too.
You may need to change the event.which though 1 = left click, 2 = middle click, 3 = right click(at least in firefox 1.5.0.5)
document.onmousedown = function(event){
if(event.ctrlKey && event.which == 1){
alert('ctrl-clicked');
}
if(event.shiftKey && event.which == 1){
alert('shift-clicked');
}
}
Comments
Voting
Votes Up
ColdKeyboard
ctiggerf
dannyboy
i_kenneth
Pio
SecondV
Sonsam
strykstaguy
sundaramkumar
ummmmm






mceppi - the IE equivalent of the which property is keyCode, I believe. That's what it is for keydown, anyway. I'm not sure if which is W3C. Cross-browser would go something like this (it's wordy, but one line):
alert('ctrl-clicked');
}
korisu: It's the same as function(arg1, arg2, e) just with a different name. Because if I put "event" as an arguement then it can be useful in IE too as window is not essential. so
function(event){
alert(event.which);
}
is the same as
function(){
alert(window.event.which);
}
in IE.