Fred
Fred

Reputation: 21

Detect if the ctrl button was pressed

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.

Upvotes: 2

Views: 667

Answers (10)

Gert Grenander
Gert Grenander

Reputation: 17094

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();
  });
});

Upvotes: 1

Mervin
Mervin

Reputation: 1113

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

Upvotes: 1

Nik
Nik

Reputation: 2484

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.

Upvotes: 0

Mervin
Mervin

Reputation: 1113

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.

Upvotes: 1

Kris van der Mast
Kris van der Mast

Reputation: 16613

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.

Upvotes: 0

powtac
powtac

Reputation: 41070

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

Upvotes: -1

Nick Craver
Nick Craver

Reputation: 630569

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.

Upvotes: 6

Lie Ryan
Lie Ryan

Reputation: 64913

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.

Upvotes: 4

shadow_of__soul
shadow_of__soul

Reputation: 427

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 :)

Upvotes: 0

unomi
unomi

Reputation: 2672

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.

Upvotes: 1

Related Questions