tags:

views:

74

answers:

10

This is what I want to do...

  1. 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 ctl+ p, and the print screen button... Can this be done...?

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...

+5  A: 

You 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 common 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.

Nick Craver
@downvoter - Helps to say **why** you disagree, otherwise it doesn't really help anyone.
Nick Craver
+1  A: 

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.

unomi
A: 

the @Nick Craver answer is right, you can't prevent it but anyways if you want to detect the key combination using mootools you have the keyboard class that let you define key combinations and add events to it:

http://mootools.net/docs/more/Interface/Keyboard

that maybe will be useful to display a warning or something like that :)

shadow_of__soul
+3  A: 

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.

Lie Ryan
+1  A: 

I agree with the answers above.

Users will always find a way around this, - A computer is not secure for copyrighted material and will never be. you need to take that into account.

Mervin
A: 
<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>
powtac
You would need to check for `.ctrlKey` here, you're checking for `alt`, regardless, please don't annoy a user like this.
Nick Craver
Not my downvote, but you should at least fix your example code :)
Nick Craver
A: 

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.

XIII
A: 

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.

Nik
+1  A: 

If you'd want to make it so that regular computer users can't do it this would help:

  1. Create an application that loads and displays the document after input of a keycode that you supply (check via webserver).
  2. the application does not have printing functions since you did not put them in
  3. register a global keyhook to blank the document if the user presses "printscreen" and show a copyright warning
Mervin
+1  A: 

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();
  });
});
Gert G
CSS - very clever;) although easy to circumvent using Firebug.
el.pescado
It's mainly aimed at making it harder for non-techies. :)
Gert G