cookieChoices = {};

Friday 24 July 2015

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>

No comments:

Post a Comment