File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes How to trap the Print Screen Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "How to trap the Print Screen" Watch "How to trap the Print Screen" New topic
Author

How to trap the Print Screen

unna kumar
Greenhorn

Joined: Oct 13, 2000
Posts: 11
In a web page I need to trap the print screen key, so that the
user cannot print my page.
what should I do for that.I tried using Javascript using clipboard property,but some times it works in Internet Explorer,
In Netscape no respond.Please give some idea.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
I have not tried this before, but I would be surprised if you could do this. The printscreen function is part of the windows environment, so you are trying to write an app that gets sent over the web to disable a clients operating system functionality. Don't know if you can do that.
Just as a side note, why would you do that? It always irritates me when I go to a site and they do something on the page that takes away some functionality that I have grown to like and expect out of my browser. Like someone was talking about disabling the right click. I always right click, and I was to go to a sight that took that away, the first thing I am going to do is disable my Javascript to see why they are doing that, because it just irritates me and makes me suspicious. I am all for designing a page using layers, dhtml, pop-ups, and letting the programmer have control of what they are doing, but disabling my browsers and windows capabilities like back buttons, history, right click, and print screen seems not worth it.
Just my thoughts.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
I agree with you Bill. Web developers must start to realize that they are visitors in my home and I expect them to treat my things with respect. I don't want them messing with my browser. Besides it just exposes that they are stupid since we can just turn off JS and revisit the site. (So what was the big secret in their code that they didn't want me to see it?)


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
The Yeti
Greenhorn

Joined: Aug 07, 2002
Posts: 1
You guys are assuming that the given website is an internet site. If you are attempting to build a browser-based intranet application, there are times when you will want to disable the printscreen key so that information can be protected.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15362
    
    6
Print Screen Kewy is the only key that can not be detected if it was pushed, sorry to say. You can detect any other key!
Anu Kha
Greenhorn

Joined: Aug 08, 2002
Posts: 3
Yup man print screen is not being detected.
I kind of am busy so cant explore this topic much but I like to add something.
Each key on the keyboard has a code like j has 106.
If u can find the code for the print screen key maybe things would work.
Here is link to place where they have a sample code to detect key strokes. See if it helps u.
http://www.htmlgoodies.com/beyond/keycapture.html
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15362
    
    6
The print screen key does not have a code, that is what i was trying to explain above. I have looked into this months ago for a project I was working on.
bhuvan sundar
Ranch Hand

Joined: Mar 02, 2005
Posts: 104
does the window key have an ASCII code? i need to capture that key. is it possible in javascript?
S Santhosh
Ranch Hand

Joined: Mar 03, 2005
Posts: 73
1) Clear the clipboard if you can, so the user when he tries to paste will lose the information.
2)Have a css for print media to disable any printing.
3)Diable print options from context menu.

But after doing all the above it will only take less than a minute to be able to print your webpage...there is still more that one way to capture a screen from browser.

So i would suggest reconsidering your options like:
Adding a watermark or putting a disclaimer if this is an intranet application or add security to restrict to specific users.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15362
    
    6
Originally posted by San Sreeds:
1) Clear the clipboard if you can, so the user when he tries to paste will lose the information.
2)Have a css for print media to disable any printing.
3)Diable print options from context menu.

But after doing all the above it will only take less than a minute to be able to print your webpage...there is still more that one way to capture a screen from browser.

So i would suggest reconsidering your options like:
Adding a watermark or putting a disclaimer if this is an intranet application or add security to restrict to specific users.


ALl useless.....You can not stop this from happening. Most browsers disable JavaScripts ability to use the clipboard. Etc. If you do not want content to be printed and saved, do not put it online.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to trap the Print Screen
 
Similar Threads
Saving a picture of an applet
Trap 'print screen' key?
Printing without print dialog
Printing at Client Side via MVC program
Print Jsf datatable issue