Connect with Expertise | Find Experts, Get Answers, Share Insights

Code to disable Print and Save As

 
Join Date: Jul 2006
Posts: 3
#1: Jul 16 '06
i need a code to disable user print and save as.if there is any javascript plz help me.last 1 month i need this code.the end user never save my pages and print my pages including text image

 
Join Date: Jul 2006
Posts: 3
#2: Jul 16 '06

re: Code to disable Print and Save As


i need disable save as javascript
sashi's Avatar
E
C
 
Join Date: Jun 2006
Location: Seremban, Malaysia
Posts: 1,743
#3: Jul 16 '06

re: Code to disable Print and Save As


Hi Baranitharan,

i have seen right click disable kind of codes around.. if you need a faster solution, you try looking in Google.com.. or else you can post your code segment on your next post and we will help you to validate your code.. take care..
sashi's Avatar
E
C
 
Join Date: Jun 2006
Location: Seremban, Malaysia
Posts: 1,743
#4: Jul 17 '06

re: Code to disable Print and Save As


Hi Baranitharan,

check out the below code.. hope it helps you to get started with.. good luck my fren.. :)

no right click for images..
Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript"> 
  2. <!--
  3. function noway(go) { if 
  4. (document.all) { if (event.button == 2) { alert(popup); return false; } } if (document.layers) 
  5. { if (go.which == 3) { alert(popup); return false; } } } if (document.layers) 
  6. { document.captureEvents(Event.MOUSEDOWN); } document.onmousedown=noway; 
  7. // --> 
  8. </script>
  9.  
no right click for source code..
Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript1.1"> 
  2. <!--
  3. var debug = true; function 
  4. right(e) { if (navigator.appName == 'Netscape' && (e.which == 3 || e.which 
  5. == 2)) return false; else if (navigator.appName == 'Microsoft Internet Explorer' 
  6. && (event.button == 2 || event.button == 3)) { alert('This Page is fully 
  7. protected!'); return false; } return true; } document.onmousedown=right; if (document.layers) 
  8. window.captureEvents(Event.MOUSEDOWN); window.onmousedown=right; 
  9. //-->
  10. </script>
  11.  
Disable Copy and Paste.
Add the following html code to your BODY tag:
Here is how your BODY tag may look once implimented:
Expand|Select|Wrap|Line Numbers
  1. <body bgcolor="#FFFFFF" ondragstart="return false" onselectstart="return false"> 
  2.  
Expand|Select|Wrap|Line Numbers
  1. ondragstart="return false" onselectstart="return false"
  2.  
Banfa's Avatar
E
M
C
 
Join Date: Feb 2006
Location: South West UK
Posts: 7,124
#5: Jul 17 '06

re: Code to disable Print and Save As


baranitharan - I do not believe there is anyway to do what you want, File -> Save As and File -> Print are functions of the browser that you have no control over as they are not part of any web standard (i.e. HTML, Javascript, CSS etc). They are things that the browser designers put in because they thought they might be useful.

sashi - the things you suggest are worst than useless IMO because they are not deterant to someone who knows what they are doing, all the do is make a site a little more irritating to use.


If you are trying to prevent someone copying something you are publishing on the web then there is only 1 answer, don't publish it. Remember just by displaying it in there browser most people already have a copy of you item in there browser cache which is easy enough to access.
 
Join Date: Jul 2006
Posts: 3
#6: Oct 15 '07

re: Code to disable Print and Save As


thanks sashi. i am try you sample code...

Hi Baranitharan,

check out the below code.. hope it helps you to get started with.. good luck my fren.. :)

no right click for images..
Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript"> 
  2. <!--
  3. function noway(go) { if 
  4. (document.all) { if (event.button == 2) { alert(popup); return false; } } if (document.layers) 
  5. { if (go.which == 3) { alert(popup); return false; } } } if (document.layers) 
  6. { document.captureEvents(Event.MOUSEDOWN); } document.onmousedown=noway; 
  7. // --> 
  8. </script>
  9.  
no right click for source code..
Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript1.1"> 
  2. <!--
  3. var debug = true; function 
  4. right(e) { if (navigator.appName == 'Netscape' && (e.which == 3 || e.which 
  5. == 2)) return false; else if (navigator.appName == 'Microsoft Internet Explorer' 
  6. && (event.button == 2 || event.button == 3)) { alert('This Page is fully 
  7. protected!'); return false; } return true; } document.onmousedown=right; if (document.layers) 
  8. window.captureEvents(Event.MOUSEDOWN); window.onmousedown=right; 
  9. //-->
  10. </script>
  11.  
Disable Copy and Paste.
Add the following html code to your BODY tag:
Here is how your BODY tag may look once implimented:
Expand|Select|Wrap|Line Numbers
  1. <body bgcolor="#FFFFFF" ondragstart="return false" onselectstart="return false"> 
  2.  
Expand|Select|Wrap|Line Numbers
  1. ondragstart="return false" onselectstart="return false"
  2.  
acoder's Avatar
E
M
C
 
Join Date: Nov 2006
Location: UK
Posts: 14,977
#7: Oct 15 '07

re: Code to disable Print and Save As


Welcome back, baranitharan. Whoa! 15 months after your original post!
thanks sashi. i am try you sample code...
Listen to the advice from Banfa. JavaScript cannot disable these things. What you should consider is why you want to do this in the first place. If it's to protect images, just watermark them. Everything appears in the cache anyway, so disabling Save As has no effect on someone that is determined enough.
 
Join Date: Mar 2010
Posts: 4
#8: Mar 12 '10

re: Code to disable Print and Save As


How to close open/save/cancel dialog box in IE 8 when user click on some button.

please sugest its urgent.
acoder's Avatar
E
M
C
 
Join Date: Nov 2006
Location: UK
Posts: 14,977
#9: Mar 15 '10

re: Code to disable Print and Save As


So you have a dialog open and you want to close it by clicking a button? or did you want something else?
 
Join Date: Mar 2010
Posts: 4
#10: Mar 15 '10

re: Code to disable Print and Save As


i need to bypass that open /save/cancel when i will click to open pdf in my web application how can i do that using some code or somewhere else./
acoder's Avatar
E
M
C
 
Join Date: Nov 2006
Location: UK
Posts: 14,977
#11: Mar 15 '10

re: Code to disable Print and Save As


If it's a browser functionality, you'll have to check the browser settings.

Do you want the PDF file to display in the browser without a dialog box or do you want to force a download?
 
Join Date: Mar 2010
Posts: 4
#12: Mar 15 '10

re: Code to disable Print and Save As


basically i have an application which will generate a consolidate pdf for all the user information at last page when user click on a button, i m calling window.open method to open that pdf in a new window,

it is working fine in IE 6 and IE 7

but in iE 8 its is opening addition popup that is open/save/cancel ,i want to avoid that using some code not using browser setting.
gits's Avatar
E
M
C
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,626
#13: Mar 15 '10

re: Code to disable Print and Save As


you might try to add a Content Disposition header with inline and filename before sending the pdf from the server ...

kind regards
 
Join Date: Mar 2010
Posts: 4
#14: Mar 15 '10

re: Code to disable Print and Save As


can u just tell me where i need to put this code.. in java file or in JSP...
gits's Avatar
E
M
C
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,626
#15: Mar 15 '10

re: Code to disable Print and Save As


you will probably have a line where the pdf is send/printed in your code? probably it will be located in a jsp-page? ...
Reply

Tags
css ondragstart