cookieChoices = {};
Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Friday, 24 July 2015

Find Mouse events using java script

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
   
</head>
<body>
    <input type="button" name="btn" value="Demo" onmousedown="riasedevent(event)" onmouseup="riasedevent(event)"
           ondblclick="riasedevent(event)" />

    <div id="results"></div>

    <script type="text/javascript">
    var result;
    function riasedevent(event) {
        result = "";
        event = event || window.event;

        document.getElementById("results").innerHTML += event.type + "<br/>";
    }

   
    </script>

</body>
</html>

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>

Disable link button default action in html

Example:

<!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 defaultactiondisable(event) {
            event = event || window.event;

            if(event.preventDefault)
            {
                event.preventDefault // this is for ie9 and later versions
            }
            else
            {
                event.returnValue = false;  //This is ie8 and earlier versions
            }
        }

    </script>
</head>
<body>
    <h1>This is demo of prevent default action of link button </h1>

    <a href="www.google.com" onclick="defaultactiondisable(event)">Go to Search</a>
</body>
</html>

Disable Browser right click



using oncontextmenu we can disable right click on browser web page.


Example:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body oncontextmenu="return false">
    <h1> This is demo of disable right click in web page</h1>
</body>
</html>

Introduction


Introduction


  • It is Scripting language.
  • make the html web pages dynamic using this.
  • creates  interactivity to html tags.
  • we can embedded the java script in to html tags.
  • open source.
  • light weight programming language.
  • case sensitive.
  • data types: numbers, Boolean and strings.
  • var is the keyword to create any of the data types.
  • dynamically typed language, datatypes are changes automatically.
  • // -- single line comment and /* -------------*/ double line comments.
  • code is placed in between the <script>...........</script> tags.