5

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

5 Answers 5

31

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.

Sign up to request clarification or add additional context in comments.

Comments

12

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.

Comments

8

As a more constructive answer, if you're talking about stopping people downloading your javascript file, you can't, however you try obfuscating/confusing/packing the script text into something pretty much unreadable.

Try this javascript obfuscator. It seems to work pretty well!

As a note, this won't stop someone who is determined, but will certainly really slow them down.

Comments

5

You can't. The page is effectively already being downloaded when you view it in the browser. If you want to protect the contents, you might be able to obfuscate the source, and depending on what you are doing you might be able to make the page non-functional once it has been downloaded (ie making some behavior of the page rely on an Ajax request to your server). But there will always be workarounds.

Comments

0
<!-- Right Click Disable -->
<script type="text/javascript">
<!-- 
var message=""; 
function clickIE() {if (document.all) {(message);return false;}} 
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) { 
if (e.which==2||e.which==3) {(message);return false;}}} 
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} 
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} 

document.oncontextmenu=new Function("return false") 
</script>
<!-- Right Click Disable -->

1 Comment

This is utterly useless, clicking Ctrl+U on Chrome will open the source, also, the user can just Ctrl+S or Settings -> Save page as..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.