Restrict viewers to inspect code from the web page

Background: We have curious and lazy minds all over the place who enjoy inspecting the web pages to view the DOM structure, or pull a snippet of code for reference. For such free spirited minds, we have a simple yet effective way to disable the “snooping around”.

Just add a few lines of code to your structure and keep your code hidden from prying eyes!

1) Restrict keyboard shortcuts
Add this code in javascript tag in your DOM structure.
    document.onkeydown = function(e) {
        if(e.keyCode == 123) {
            return false;
        }
        if(e.ctrlKey && e.shiftKey && e.keyCode == ‘I’.charCodeAt(0)){
            return false;
        }
        if(e.ctrlKey && e.shiftKey && e.keyCode == ‘J’.charCodeAt(0)){
            return false;
        }
        if(e.ctrlKey && e.keyCode == ‘U’.charCodeAt(0)){
            return false;
        }
        if(e.ctrlKey && e.shiftKey && e.keyCode == ‘C’.charCodeAt(0)){
            return false;
        }      
    }

2) Restrict right click
Just add one attribute in the body tag.
Example :
    <body oncontextmenu=”return false;”>
        <!–
                …Your Code Here…
        –>
    </body>

Categories: Website Development

Leave a Reply

Your email address will not be published. Required fields are marked *

Share: