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

10-13-2005, 02:57 PM
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?

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,