I want to disable Ctrl+U from browser to stop users viewing the source (html + JavaScript) for a page.
-
6I assume by Ctrl-U you mean "View Source" – you can't prevent that. – tobiv Dec 05 '16 at 10:59
-
Yes I want Ctrl+U for View Source, and I am able to do so but if I apply Ctrl+U my F12 and right click is not working – NARGIS PARWEEN Dec 05 '16 at 11:01
-
2Although you can override the Ctrl+U keybind, you can't disable browser functionalities. – Alexandru Severin Dec 05 '16 at 11:04
-
1How does that make anything safer? The source code can be read by anyone. Disabling a keybind wont prevent anyone from viewing the source code. Stop trying to do so and focus on important things. – Charlotte Dunois Dec 05 '16 at 11:11
-
why do you wanna hide your source? – Masivuye Cokile Dec 08 '16 at 11:59
3 Answers
This unfortunately is not how it works.
When a user visits your website, there's a lot going on behind the scenes:
- The user queries a page on your site.
- Your server does some fancy things
- Your server transforms those fancy things into something for the users browser to use
- Your server sends off its final product back to the browser.
- The browser then gets a bunch of code, such as HTML or Javascript.
- The browser then reads that HTML and Javascript and organizes it to look and work how it's supposed to on the users screen.
Basically, another way of saying all this, is that the HTML and Javascript that you want to hide is executed client-side. This means that your browser gets a bunch of code, it executes it, and then displays its results to the user. If someone really wanted to see the source code of your website, they could easily bypass your prevention of using CTRL+U
. All they have to do is to somehow tell the browser not to execute the code!
Ultimately, if a user really wants to see your source code, they will do it. There is no way to stop it. For this reason, it is recommended to keep things you need to remain a secret on the server-side code (such as your PHP).

- 9,621
- 3
- 48
- 81

- 1,689
- 2
- 16
- 26
You potentially can not prevent user from viewing the html source content. The site that prevents user from rightclick. but Fact is you can still do Ctrl+U in firefox and chrome to view source !
It is impossible to effectively hide the HTML, JavaScript, or any other resource sent to the client. Impossible, and isn't all that useful either.
Furthermore, don't try to disable right-click, as there are many other items on that menu (such as print!) that people use regularly.
Please have a look at this
I think this may help you.
Unfortunately CTRL+U is for "View Source", you can't disable browser functionalities, but you can write secure coding whichever you don't want to show.

- 22,678
- 7
- 27
- 43

- 4,696
- 7
- 43
- 97