Control+click action in javascript.





10
Date Submitted Wed. Sep. 27th, 2006 11:03 AM
Revision 1 of 1
Scripter shachi
Tags click | Control | ctrl/shift | JavaScript
Comments 3 comments
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)

document.onmousedown = function(event){
if(event.ctrlKey && event.which == 1){
alert('ctrl-clicked');
}
if(event.shiftKey && event.which == 1){
alert('shift-clicked');
}
}
 

Shachi Bista

Comments

Comments cross scripting?
Mon. Oct. 2nd, 2006 7:32 PM    Helper mceppi
  Comments arguments?
Wed. Oct. 4th, 2006 9:24 PM    Newbie korisu
    Comments Sorry ..
Sun. Nov. 12th, 2006 2:02 AM    Scripter shachi

Voting