how to disable CTRL+U and F12 in pure html code in order to restrict user to see my source code on a web page
-
2Simply, you can't. – Mohammad Usman May 01 '18 at 07:31
-
4Possible duplicate of [How to hide html source & disable right click and text copy?](https://stackoverflow.com/questions/6597224/how-to-hide-html-source-disable-right-click-and-text-copy) – Syed Waqas Bukhary May 01 '18 at 07:43
-
2no need to bother your self with this. Focus on coding instead of trying to hide your code. – Temani Afif May 01 '18 at 08:15
1 Answers
You can use JavaScript to prevent right-clicks and some function keys, depending on browser. However, I'd strongly advise doing so as you'll annoy users who use the context menu and potentially impact accessibility.
Anyway, if you really want to disable right-clicks, you can use this, or any other implementation of it you see fit. Note that this will not prevent right-clicks if the user has JavaScript disabled:
<body oncontextmenu="return false;">
I could not find a way to prevent F12 and Ctrl+U - the most I managed was to detect when F12 was pressed, and even that didn't work in Chrome. So making it harder to access the source code isn't really an option. Not that disabling those keys would be enough, of course - you can always use your browser's menu.
What you can do is obfuscate your HTML. This relies on JavaScript, can easily be reversed and is a complete waste of your time, but here's one tool that does just that: http://snapbuilder.com/code_snippet_generator/obfuscate_html_source_code/ It works by storing your HTML as escaped characters then unescaping it all. Pretty primitive stuff.
TL;DR: You can't and you shouldn't try to.

- 626
- 5
- 19