• Disabling Right-Clicking Using JavaScript


    The following JavaScript code will prevent the default right click when the right mouse is clicked in web page to stop visitors from easily stealing copyrighted contents from website.
    Put the javascript code as follows in
    <head></head>.

    <html>
        <head>
            <title></title>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <script type="text/javascript"> 
                var message="right-click has been disabled"; 
                function clickIE() {if (document.all) {(message);return false;}} 
                function clickNS(e) {if 
                (document.layers||(document.getElementById&&!document.all)) { 
                if (e.which==2||e.which==3) {(message);return false;}}} 
                if (document.layers) 
                {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} 
                else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} 
                document.oncontextmenu=new Function("return false") 
                </script> 
        </head>
        <body>
            <h1>hello</h1>
        </body>
    </html>

  • You might also like

    No comments:

    Post a Comment