Compatibility of mouse buttons

Source: Internet
Author: User

<! 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.