I want to prevent users from printing a page I thought I would set the screen to not include the toolbars, and prevent right clicks, and prevent Ctrl+ P, and the Print Screen button. Can this be done?
Is there any good code out there for this? I have searched quite a bit so far, but not much luck. I know this isn't foolproof, but it will prevent some users from copying or printing.
I want to prevent users from printing a page I thought I would set the screen to not include the toolbars, and prevent right clicks, and prevent Ctrl+ P, and the Print Screen button. Can this be done?
Is there any good code out there for this? I have searched quite a bit so far, but not much luck. I know this isn't foolproof, but it will prevent some users from copying or printing.
Share Improve this question edited Jan 25, 2013 at 6:23 Rapptz 21.3k5 gold badges73 silver badges87 bronze badges asked Jun 20, 2010 at 11:52 FredFred 211 bronze badge 4- 9 Forget it. You can't stop people print or copy or use their browser in any way they want. The only solution is: If you don't want your content to printed or copied, then don't put it ion the web. It's that simple and there is no other way. – RoToRa Commented Jun 20, 2010 at 12:00
- @RoToRa - There are legitimate reasons for preventing certain normal features. One could be that it's a public terminal. Another is for security reasons. – Gert Grenander Commented Jun 20, 2010 at 12:05
- @Gert: ... but that wouldn't be done in JS (it would be better to remove the print and the ctrl key from the keyboard :-) – Chris Lercher Commented Jun 20, 2010 at 12:27
- @chris_l - Ideally, remove keyboard and mouse, maximize the browser and use a touch screen. ;) – Gert Grenander Commented Jun 20, 2010 at 12:44
10 Answers
Reset to default 6You can't do this...you can't disable the user's ability to print, nor should you try.
Ctrl+P is the way a programmer prints, File > Print (depending on browser) is the way the typical user does...so this wouldn't even disable the most mon method. In addition, any decent programmer can get around this anyway, so it effectively doesn't stop anyone.
Any data you get to a user, displayed or not, they can see, copy, print, etc...there's nothing you can do to prevent this, definitely not 100%. If this is one of your requirements...you should be asking if a website is the best way to deliver this data.
By doing that, you will annoy legitimate users, and if you think a serious copyright violator uses a regular browser (whose printing function you can disable), then you're very mistaken.
On the one hand information wants to be expensive, because it's so valuable. The right information in the right place just changes your life. On the other hand, information wants to be free, because the cost of getting it out is getting lower and lower all the time. So you have these two fighting against each other. source
Also:
Information Wants To Be Free, and Code Wants To Be Wrong.
I agree with the answers above.
Users will always find a way around this, - A puter is not secure for copyrighted material and will never be. you need to take that into account.
If you'd want to make it so that regular puter users can't do it this would help:
- Create an application that loads and displays the document after input of a keycode that you supply (check via webserver).
- the application does not have printing functions since you did not put them in
- register a global keyhook to blank the document if the user presses "printscreen" and show a copyright warning
A couple of years ago, I built an exam system where one of the requirements was to make it hard for people to print the exams. Removing the print functionality is as we know, impossible (unless you do some changes in the browser software). What you can do is to make it harder for non-technical people to print the page. E.g. Use CSS to blank the page when it goes to the printer:
<style type="text/css">
@media print {
body { display:none }
}
</style>
The following jQuery script will prevent copy&paste in some browsers:
$(document).ready(function () {
$(document).bind('copy paste', function (e) {
e.preventDefault();
});
});
the @Nick Craver answer is right, you can't prevent it but anyways if you want to detect the key bination using mootools you have the keyboard class that let you define key binations and add events to it:
http://mootools/docs/more/Interface/Keyboard
that maybe will be useful to display a warning or something like that :)
You could so with jQuery for example. However think of this: a browser runs on a client pc which is owned by someone. That person should be in control of what happens on his/her device. It's not up to you to start putting scripts to get rid of standard functionality the enduser might want to use.
If you don't want something to be printed then don't show it on a public place. If it's confidential, treat it as such.
Grz, Kris.
Take this into account. I agree with the other answers and present another way around this. All the user must do is take a screenshot, which involves the application layer of the operating system, and one of which you cannot even hope to change. On Ubuntu, it's even in the user's main menu to do this.
<script type="text/javascript">
function detectspecialkeys(e){
var evtobj=window.event? event : e
if (evtobj.altKey)
alert("you pressed 'Ctrl'");
evtobj.preventDefault();
}
document.onkeypress=detectspecialkeys
</script>