-2

I'm attempting to deactivate inspect on my server or website so that others can't view my code and other reasons; I'm sorry if this seems too insecure, but if there's a method, please tell/show me... I've been researching and have discovered some solutions, but I've tried and failed. Here is the code for what I attempted.

_document.js:

<Html onContextMenu={false}>
 <Head>
 {...}
 </Head>
 <body onContextMenu="false">
 {...}
  <Script>
   {`document.addEventListener('keydown', function() {
     if (event.keyCode == 123) {
       alert("You Can not Do This!");
       return false;
     } else if (event.ctrlKey && event.shiftKey && event.keyCode == 73) {
       alert("You Can not Do This!");
        event.preventDefault();
       return false;
     } else if (event.ctrlKey && event.keyCode == 85) {
       alert("You Can not Do This!");
       return false;
     }
   }, false);
  
   if (document.addEventListener) {
     document.addEventListener('contextmenu', function(e) {
       alert("You Can not Do This!");
       e.preventDefault();
     }, false);
   } else {
     document.attachEvent('oncontextmenu', function() {
       alert("You Can not Do This!");
       window.event.returnValue = false;
     });
   }
 `}
 </Script>
</body>
</Html>

All of the necessary imports are also present... I appreciate your assistance!

Atif Khan
  • 23
  • 5
  • People cannot inspect your server-side code unless you give it to them. Client-side code can always be inspected. For the reason alone that you cannot reliably distinguish a browser from any other HTTP client. – idmean Dec 15 '21 at 13:41
  • What exactly do you mean by "unless you give it to them"? It is enabled by default on all devices. but thanks for the response – Atif Khan Dec 15 '21 at 13:43
  • The ability to inspect the source code (HTML/CSS/Javascript) on a webpage is controlled by the browser. While you can do things like try to disable right-click or certain keys, you can never completely stop a user from being able to do this as browsers do not allow that functionality to be disabled. – EssXTee Dec 15 '21 at 13:44
  • @AtifKhan "deactivate inspect on my server" I was referring to this part of your question. It's not very clear, so maybe I misunderstood you. – idmean Dec 15 '21 at 13:45
  • @EssXTee i think I saw a website that i couldnt inspect with but i understand now, thanks fo your answer and reply. i appreciate it! :) – Atif Khan Dec 15 '21 at 13:45
  • @idmean im so sorry im new to stackoverflow and i also read the instructions on making questions, and sorry for not explaining well... – Atif Khan Dec 15 '21 at 13:46
  • @EssXTee im fine with disabling right click and disabling inspect shortcuts can you help me? – Atif Khan Dec 15 '21 at 13:47
  • You should probably know about this option in Chrome: https://stackoverflow.com/questions/12212504/automatically-open-chrome-developer-tools-when-new-tab-new-window-is-opened There are multiple ways to automatically open dev tools in new tabs. Minifying and obfuscating is a much better protection than disabling right-clicks. – jabaa Dec 15 '21 at 14:04

1 Answers1

1

No, there's no way to do that.

There might be some workarounds like blocking right click for example, but in general, source code of the webpage/website isn't something you can protect against copying/stealing because that's how Web works. Whoever wants to see your source code might simply get it even without browser, if needed.

dlzs
  • 26
  • 3