HTML and CSS Reference
In-Depth Information
Table 13.10 Button Values
Microsoft Internet Explorer
W3C/Mozilla/Firefox
event.button
event.which
Left button = 1
Left button = 0
Middle button = 4
Middle button = 1
Right button = 2
Right button = 2
EXAMPLE 13.24
<html>
<head><title>Mouse Buttons</title>
<script>
function whichButton(e) {
var button;
1
if (!e) {var e = window.event;}
2
if(e.which){ button = e.which;}
3
else if(e.button){ button=e.button; }
alert(button);
4
switch(button){
case 0:
return("FF leftclick");
break;
case 1:
return("leftclick");
case 2:
case 3: // Firefox returned 3 on the Mac
return("rightclick");
break;
case 4:
return("IE middleclick");
}
}
</script>
</head>
<body>
&nbsp;&nbsp;Click the mouse in the green box
<div onMousedown="alert(whichButton(event)) ;"
style="position:absolute;top:100;left:20;
height:200;width:200;background-color:green">
</div>
</body>
</html>
 
Search WWH ::




Custom Search