Reputation: 179
I want to prevent my web site from save As functionalily of browser. My site have some javascript file too. Is there any source code to prevent from save as the web site from browser or source code for encryption of site.
Thank you
Upvotes: 0
Views: 6832
Reputation: 21
There is a much easier method, all you need to do is put the following. Been using this method for years and no one has gotten around it.
<body oncontextmenu="return(false);">
Although I recommend for debug purposes you put something in there to allow you to see it something like the following
<body oncontextmenu="return(event.crtlKey);">
This will allow the user to view the context menu if you hold the Control Key while right clicking.
Upvotes: 2
Reputation: 15493
By definition you can't prevent your site from being downloaded, because that is what every user's browser is doing to display it.
The most you can do is obfuscate your code, which makes it more difficult for anyone to re-use components of your website. If you do a search for JavaScript, CSS or HTML obfuscators you find quite a few.
The other option is to try and make it more difficult or annoying for them to download it, by using JavaScript to change the behavior of the mouse buttons. (Search for right-click disable scripts)
EDIT:
Note that I don't recommend doing either of these. Neither option is perfect and in the end just frustrates your users.
Upvotes: 6
Reputation: 6310
Since the web page and its related content is downloaded to the computer of the user browsing your web site, it is already saved to the user's computer. Therefore it is impossible to prevent the user from accessing the save-functionality.
However, you can obfuscate your code - read this post on the programmer-to-programmer forums. As mentioned in the post, if you have sensitive information you don't want the user to access, you'll have to find another approach which does not involve storing sensitive information in .js files or in the web page itself.
Upvotes: 4
Reputation: 99869
Not really, and it's extremely annoying when sites do this. All it means is I have to take 5 seconds to go through Web Developer Toolbar to disable whatever it was and try again.
Although pages dynamically loaded with AJAX code tend to be difficult to save with the current state.
Upvotes: 4
Reputation: 12897
you cant prevent people from saving a web page. You can mess around in js, you can prevent right click, but everything you try will be useless because we can still get your images and your source code. You cannot disable stuff like that on all browsers, infact its hard to stop someone from getting that data in even ie because of the fact that the user has to download your web page for his browser to read the code... all of your code ends up in his cache which he can just go into and look at. Quit trying to protect your client side source code and images... its impossible.
Put the following script in the head of your page: to DISABLE RIGHT CLICK
<script language="JavaScript">
// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this header.
// ----------- Setups ------------------
// Set the address, width, height, top
// and left dimensions for the popup
// window below.
// -------------------------------------
PopUpURL = "http://www.yoursite.com/yourpage.html";
PopUpLeft = 100;
PopUpTop = 100;
PopUpWidth = 500;
PopUpHeight = 100;
// -------------------------------------
// Do not edit anything below this line.
// -------------------------------------
isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
popO='left='+PopUpLeft+',top='+PopUpTop+',width='+PopUpWidth+',height='+PopUpHeight
if (isIE||isNN){
document.oncontextmenu=checkV;
}else{
document.captureEvents(Event.MOUSEDOWN || Event.MOUSEUP);
document.onmousedown=checkV;}
function checkV(e){
if (isN4){
if (e.which==2||e.which==3){
dPUW=window.open(PopUpURL,'nrc',popO);
return false;
}}else{
dPUW=window.open(PopUpURL,'nrc',popO);
return false;}}
</script>
Additional Notes:
In the popup window that you open with this script, you may wish to add onload="self.focus()" to the body tag, as shown immediately below. This forces the popup to come to the front.
<body onload='self.focus()'>
Upvotes: -2
Reputation: 10536
IMO there is nothing you can do, as the user allready have downloaded your page on his hard drive to see it. The "Save As" functionnality is just a simple cut/paste of html and picture located in Temporary Internet Files (or wherever else). Why would you need to prevent this ?
Upvotes: 10