 |
| Javascript General Javascript discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 24th, 2005, 03:22 PM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Disable print screen
Hi,
I have an ASP web page that displays some text. I want to put in place a few things to make it difficult for this text to be printed/copied to be passed on to others. This is because the text is to be seen by one person at a time after they log in.
I have placed some Javascript on the page that stops (or hinders) the user from selecting the text to copy, and also stops (hinders) him from printing the page, and also stops him loading that page outside its current frameset (hence making it difficult to get to see the source code).
My question: I know it is possible to add something to disable (or hinder) the print screen button. The reason I know this, is because some of the off-the-shelf "HTML Encryptors" offer this feature (and they work, because I have tried them). I don't want to encrypt my code, but I DO want to add a script to disable the print screen button.
If you know what that script is, please will you post it here.
Please please please... I do not want a discussion about the whys/if/maybes of whether we *should* disable the print screen button. I have read all that already and it is not relevant to me. Nor do I need to know (again) that no method is 100% reliable (that is not my aim). Trust me that this is a valid request.
Hope you can help.
Thanks.
Steve
P.S. Actually, I believe that this is more about disabling the clipboard than the print screen button... please tell me what the script is, if you know. Thanks.
|
|

January 24th, 2005, 03:32 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
AFAIK, this is not possible.
This is not a browser feature, but an OS feature.
Out of curiosity, how did you disable printing?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Aqueous Transmission by Incubus (Track 13 from the album: Morning View) What's This?
|
|

January 24th, 2005, 05:00 PM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar - exactly what I thought. However, if you install and run the HTML Encryptor called "HTML Guardian" from http://www.protware.com (there is a version you can get for free) you will see that it generates an encrypted script that somehow manages to disable a screen-print (when that window has the focus, at least). As the script is all encoded, I have no idea how it does this. I would like to find out.
|
|

January 24th, 2005, 05:07 PM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
By the way, "HTML Guardian" worked perfectly. However, although the result encrypted page was served up fine on my local IIS server, it did NOT download from my main web server. I suspect this is because our firewall was suspicious of the content of the page. If that is the case, then an encrypted file like that is no use to me, as I have to be sure that it will work OK for each of my clients. I have therefore abandoned it for now.
Instead, I am using the following scripts. These hinder text-selection and printing (although of course they do not prevent someone looking at the source and copying that). Works fine in IE6 (and, I am told, IE4).
Place the following WITHIN THE HEAD SECTION of an HTML page.
This disables text selection, disables the right-click pop-up menu
and will cause only blank pages to be printed when user selects "print"
(for which you need to place the file "print.css" in the same folder).
================================================== ===============
<link rel="stylesheet" type="text/css" href="print.css" media="print">
<script language="JavaScript">
function disableselect(e)
{
return false
}
function reEnable()
{
return true
}
document.onselectstart=new Function ("return false")
//if NS6
if (window.sidebar)
{
document.onmousedown=disableselect
document.onclick=reEnable
}
function rightclick()
{
if (event.button==2)
{
alert("menu disabled")
}
}
document.onmousedown=rightclick
</script>
================================================== ===============
print.css is a separate file containing this:
body {
display: none;
visibility: hidden;
}
Hope this is useful to some of you.
|
|

January 24th, 2005, 07:18 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
In agreement with Imar, I don't think there's a way to disable print screen with JavaScript or any other web language. I've seen it done in applications, but a web page is only data displayed in an already running application.
However, you might experiment with calling a function that returns false when you click the print screen button, something like:
document.onkeydown = function(event){if(event.keyCode==PRINT SCREEN's KEYCODE)return false;else return true;}
I don't think it will work, but perhaps it will.
Good luck,
-Snib - http://www.snibworks.com
Where will you be in 100 years?
|
|

January 25th, 2005, 05:57 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
HTML Guardian appears to disable print screen by continually pasting from the clipboard. If you disable this in internet settings then it doesn't work.
--
Joe ( Microsoft MVP - XML)
|
|

January 25th, 2005, 01:39 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Interesting solution....
But, like any other possible solution: if it's out there on the Internet, you can get it and then print it or do whatever you want to do with it..... ;)
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

January 26th, 2005, 11:28 AM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
All very interesting posts, but - getting back to the question I asked:
Does anyone actually KNOW what the script is that achieves what "HTML Guardian" is doing to disable print screen?
That, guys, is all I want.
Snib - I'll try your idea, but even if it doesn't work, there MUST be a script that does it, because I've seen it... generated by "HTML Guardian"... except in encrypted form!!!
|
|

June 1st, 2005, 06:08 AM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Joe, many thanks. (Sorry for long delay in responding!)
I will try this out. I get the feeling that you are right about this being the method used by "HTML Guardian". I suppose it is a rather "nasty" solution in so far as you are deliberately wiping out the user's clipboard... and they may have something on it that they really need!
Perhaps this is a good technique for use on web sites that are designed to hurt the user:
"Come to our web site... we'll hurt you!"
:)
|
|
 |