How To Prevent View Source Of Page Using Javascript?
Solution 1:
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.
Solution 2:
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.
Solution 3:
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.
Solution 4:
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.
Solution 5:
<!-- Right Click Disable --><scripttype="text/javascript">
<!--
var message="";
functionclickIE() {if (document.all) {(message);returnfalse;}}
functionclickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);returnfalse;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=newFunction("return false")
</script><!-- Right Click Disable -->
Post a Comment for "How To Prevent View Source Of Page Using Javascript?"