cookieChoices = {};

Friday 24 July 2015

Find Which mouse button is clicked

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">

        document.oncontextmenu = defaultactiondisable; // this line is to disable right click on web page

        function btnidentifyfunction() {
            var btnresult;

            if (event.which) {
                switch (event.which) {

                    case 1: btnresult = "left one"; break;
                    case 2: btnresult = "mid one"; break;
                    case 3: btnresult = "right one"; break;
                    default: btnresult = "invalid"; break;
                }
            }
            else {
                switch (event.button) {

                    case 1: btnresult = "left one"; break;
                    case 2: btnresult = "mid one"; break;
                    case 3: btnresult = "right one"; break;
                    default: btnresult = "invalid"; break;
                }
            }

            document.write(btnresult);
        }
       
    </script>
</head>
<body>
    <h1>This is demo to identify which mouse button is clicked</h1>

    <input type="button" name="name" value="Demo" onclick="btnidentifyfunction(event)" />
</body>
</html>

No comments:

Post a Comment