Rss Feed Like Us on facebook Google Plus

August 7, 2013

Disable Right Click Button - Javascript

while developing web application ,some situation arises where we have to disable right click button of a mouse in web pages of Asp.Net,PHP ,JSP. you can achieve this by using Javascript.

Qusetion - How to disable right click button of mouse in webpage.

Solution- 
add below script in head section of web page

<script type="text/javascript">
        var msg = "This function is disabled!";
        var bV = parseInt(navigator.appVersion)
        var bNS = navigator.appName == "Netscape"
        var bIE = navigator.appName == "Microsoft Internet Explorer"
 
        function nrc(e) {
            if (bNS && e.which > 1) {
                alert(msg)
                return false
            } else if (bIE && (event.button > 1)) {
                alert(msg)
                return false;
            }
        }
 
        document.onmousedown = nrc;
        if (document.layers) window.captureEvents(Event.MOUSEDOWN);
        if (bNS && bV < 5) window.onmousedown = nrc;
    </script>
..........................................................................................

Read Also...

How to prevent page going back on backspace button click

© 2011-2016 Techimpulsion All Rights Reserved.


The content is copyrighted to Tech Impulsion and may not be reproduced on other websites.