Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent View Source of page using Javascript?

Tags:

javascript

How to prevent to download the source code of page using File > Save as?

like image 401
Vicky Avatar asked Oct 10 '09 07:10

Vicky


2 Answers

It's not possible and you shouldn't even bother trying it, because:

  • The users who realize, there is a source, will most likely have the knowledge to download it anyway.
  • The normal users, who are unaware of the whole source concept are only annoyed by the futile attemps to block the source ("Why is my right mouse button not working on this site? All I want to do is create a bookmark.")

Just look at Microsoft, Amazon, and Co., but also at sites like DeviantArt: All these businesses obviously spent a lot of effort (=money) into their sites, and they don't do anything to prevent the source access.

On the other hand I've seen many small private sites, with no real content or value other to the creator of the pages, which try to prevent accessing their source.

As a rule of thumb: Any kind of copy control technique, which harasses your legitimate customers, doesn't pay off and will damage your business in the long run.

like image 123
Daniel Rikowski Avatar answered Sep 23 '22 02:09

Daniel Rikowski


You cannot prevent this behavior. Even if you were to be able to prevent it in any particular browser, you are still delivering code content that browsers render for you, someone could just create a raw request and view the source.

like image 23
Quintin Robinson Avatar answered Sep 22 '22 02:09

Quintin Robinson