NARGIS PARWEEN
NARGIS PARWEEN

Reputation: 1596

How to prevent browser Ctrl+U?

I want to disable Ctrl+U from browser to stop users viewing the source (html + JavaScript) for a page.

Upvotes: 1

Views: 3098

Answers (3)

Mr world wide
Mr world wide

Reputation: 4814

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.

Upvotes: 1

Pranav MS
Pranav MS

Reputation: 2296

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.

Upvotes: 3

robere2
robere2

Reputation: 1716

This unfortunately is not how it works.

When a user visits your website, there's a lot going on behind the scenes:

  1. The user queries a page on your site.
  2. Your server does some fancy things
  3. Your server transforms those fancy things into something for the users browser to use
  4. Your server sends off its final product back to the browser.
  5. The browser then gets a bunch of code, such as HTML or Javascript.
  6. 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).

Upvotes: 3

Related Questions