Block access to a website’s source code

Asked

Viewed 1,339 times

2

Is there any way to block access to the source code of a website in firefox, chrone, Opera and Safari browsers, preventing access in the following ways through the right mouse button, use of control+u keys or direct access through the browser menu by the option to view source code ?

  • 1

    loss of time and investment.. At most, what you can do is obfuscate.. this amazes many curious, however, who really wants to read the code will be able to decode anyway... so it is a waste of time even for those who keep the system because to debug an eventual error, for example, it is a nightmare... Remember that pages can be accessed even without a browser.

2 answers

7


The code executed by the client-side is accessible by the user. The most you can do is to block the right mouse button and keys through Javascript, but you cannot prevent the user from accessing the browser menu. Minifique the JS, to make it difficult to read who try to view the source.

Remember: Business rules must be executed on the server-side.

1

Yes it is possible, you for example can use some functions in JS.

`

var message="";
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")


//  F12
//==========

  document.onkeypress = function (event) {
    if (e.ctrlKey &&
        (e.keyCode === 123)) {
            // alert('not allowed');
            return false;
          }
  };


//    CTRL + u
//==============

  document.onkeydown = function(e) {
    if (e.ctrlKey &&
      (e.keyCode === 85)) {
          // alert('not allowed');
          return false;
        }
      };  

`

You can see which is the number of the key you want to block through the site: http://www.foreui.com/articles/Key_Code_Table.htm

  • The code you posted may even work, but as some have said, this type of treatment is not practical. Because we can disable the JS page, or read the site without a browser using Curl for example.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.