Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide source code and inspect element via javascript or jquery?

I want to disable my webpage source code and inspect element bar. And I did it with this script. But if I wrote " view-source: " before my url the source code will be shown. How can I fix this? Is there any possibility to hide source code? Good answers must be appreciated

<script>

  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;
    }      
 }

</script>
like image 335
Jishnu V S Avatar asked Aug 12 '16 05:08

Jishnu V S


2 Answers

There is no way to hide the JS code. JS-Scripts are running inside your Browser. So the Browser must know the JS-Scripts. And if the Browser know it, the user can have a look at them. You could only try to compress them, to avoid to easy reading by user.

Use https://jscompress.com/ if you have a static JS-Script

like image 87
Marcus Avatar answered Sep 18 '22 06:09

Marcus


There is no way to hide source code & inspect element, but all you can do is disable the the right click of mouse button using

    function disableclick(event){
           if(event.button==2){ // this value is 3 for some othe browser
            // Rest of code
         return false;    
       }
    }
document.body.onclick = disableclick()

Also not that you need to disable F12 key since pressing F12 open the developers console, which is actually bypass right click event

like image 20
brk Avatar answered Sep 17 '22 06:09

brk