<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<script>
Window.onload=function () {
Document.onmousedown=function (event) {
Alert (Getbutton (event));
if (Getbutton (event) ==0) alert ("left Key");
if (Getbutton (event) ==1) alert ("Middle key");
if (Getbutton (event) ==2) alert ("Right-click");
};
};
/* Window.event This property is supported by IE browser, Chrome is also supported, if all support, it is the internet * * *
function Getbutton (event) {
var e=event| | window.event; Compatibility of Event
if (event) {//if supported, return directly
return E.button;
}else if (window.event) {//If not supported, execute the following program
Switch (E.button) {
Case 1://1 is the left key of IE
return 0; Properties in non-IE (Internet Explorer), 0 for left key
Case 4://4 means the middle key of IE
return 1; Properties in non-IE (Internet Explorer), 1 for Middle key
Case 2://2 means IE right-click
return 2; Properties in non-IE (Internet Explorer), 2 means right-click
Case 0://360 browser 0 means right-click
return 2; Properties in non-IE (Internet Explorer), 2 means right-click
}
}
}
</script>
<body>
</body>
Compatibility of mouse buttons