...

View Full Version : Modifier key recognised with an ahref/onClick event?



RichardJW
10-13-2005, 01:57 PM
Hi,
I've been trying to get an onclick event to check for the SHIFT key and branch accordingly. I've had limited success, finding no robust script to do this cross browser/DOM. I posted a thread a short while ago, but had no responses; there is more information about what I am looking for there: Previous thread (http://www.codingforums.com/showthread.php?t=69531)

Anyway I did some more searches on the forums & found this script which checks for a click event in the document. It seems to work across a good proportion of modern browsers.

Could anyone tell me how I can successfully use this on a standard <a href"#"..> link?



document.onclick=function(e){
if (!e) e=event;
if (e.ctrlKey){
alert("CTRL key is pressed.");
}
else if (e.shiftKey){
alert("SHIFT key is pressed.");
}
else if (e.altKey){
alert("ALT key is pressed.");
}
else {alert("Single click.");
}
}

Any help/advice would be much appreciated,

RJW.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum