-1

I just want to block the user from taking printed copy of the web page. I know that this is not user friendly, but, this is a special scenario, an examination interface where an examinee will attempt questions in an exam. So I don't want them to take prints of the page. I have also blocked other necessary options like context menus, alt Key, save as html etc eventhough it's not good in user's specific view.

I have done it using Jquery, but the code is not working in Safari.

Code:

$(document).keydown(function(event) {
// Disable Ctrl+P.

   if(!event) event = window.event;
   if (event.ctrlKey && (event.which === 80)) {
     event.preventDefault();
     alert(event.isDefaultPrevented());
   }
});

But, the alert is showing the value 'true' and then prompting with Print dialogue box. I have tried by putting return false instead of event.preventDefault();, then also not working. I couldn't figure out why this weird behaviour in Safari only. Please help. Thanks :)-

Rajesh Omanakuttan
  • 6,788
  • 7
  • 47
  • 85
  • 3
    Please *don't* prevent your users from doing anything; any code you have *is* bypassable, and this will only serve to frustrate your users. You realize that users can use context menus as well? – Kevin Ji Jan 21 '14 at 06:34
  • 2
    This is the wrong way to do it. They can still use `Print` from the menu. – Barmar Jan 21 '14 at 06:34
  • 2
    I hate websites that try to do this sort of thing. The only way to protect your content is not to publish it. My Print menu still works fine (and many users don't even know what Control-P does) – Andrew Barber Jan 21 '14 at 06:34
  • Fun fact: modern web-browsers understand `@media print`. – user2864740 Jan 21 '14 at 06:35
  • possible duplicate of [Catch "Command+R" in Safari with JQuery](http://stackoverflow.com/questions/7738139/catch-commandr-in-safari-with-jquery) – Scary Wombat Jan 21 '14 at 06:36
  • 3
    Thank you all. I agree with you all. But, this is a special scenario, an examination interface where an examinee will attempt questions in an exam. So I don't want them to take prints of the page. I have also blocked context menus, alt Key, save as html etc. – Rajesh Omanakuttan Jan 21 '14 at 07:28
  • 3
    Those who have down voted, I didn't get such a link when I searched for my query. So, how can this be a duplicate question? Also, do I need to make sure that no such related questions are there inside Stack overflow when I'm sincerely putting a query? If so, it is not fair at all. – Rajesh Omanakuttan Jan 21 '14 at 07:32
  • Have you blocked the user from hitting `Prt Scr`? How about from taking a picture with a cameraphone? – Blorgbeard Jan 21 '14 at 21:24
  • Blorgbeard: I've tried. But, later came to know that Print Screen, Alt+Tab etc. keys are Special Keys and hence they can't be prevented normally. Then, if the examination demands security of questions in that exam, we will try to provide it in whatever ways we can. About Camera phone, yes it is possible. But, if the examiners are concerned about that, then they can put invigilators for checking the same. Even then, an examinee wants to do something wrong purposefully, our system is not supposed to prevent him physically from doing the same. – Rajesh Omanakuttan Jan 22 '14 at 03:52

1 Answers1

0

You can try this code:

$(document).on("keyup keydown", function(e){
    if(e.ctrlKey && e.keyCode == 80){
        alert('Ctrl + P pressed!');
        return false;
    }
});

Demo

Felix
  • 37,892
  • 8
  • 43
  • 55