shld read "The printscreen key code...."
Main Topics
Browse All TopicsHi:
I would like to know is there any code by which I can disable the printscreen function in keyboard? I see there are some script or code can disbale the right mouse click. So, I am looking something like this.
Thanks in advance.
rsdn
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
rsdn,
just as a general note, i get the impression that you are trying to prevent users saving permanent copies of your sites content, or something to this effect...
(If this is not the case please feel free to ignore the following)
I would not advise dedicating too much of your time to this cause as it is virtually impossible to achieve. For example, if you was trying to stop users saving images then you *could* disable the right click using JavaScript however there are ways of getting around it, namely disabling JS in the browser. Further more remember that everything you view on the web is downloaded into the temp internet files so everything can be dragged out of the temp files folder if the user wishes to do so. Basically, if you don't want users to be able to save your files its best not too put them online.
I hope that was in some way helpful.
Diablo
Paste this into the head of your page:
<head>
<script language="javascript">
<!--
function clearData(){
window.clipboardData.setDa
}
browserName = navigator.appName
browserVersion = parseInt(navigator.appVers
document.onmousedown = checkforRightMouseButtonCl
if (browserVersion<5 && browserName=="Netscape")
{
window.onmousedown = checkforRightMouseButtonCl
}
function rightClickPressed()
{
alert("For Security reasons, Right-click has\nbeen disabled for this Web Page\n\nSorry for any inconvenience.");
}
function checkforRightMouseButtonCl
{
if ( ((browserName != "Microsoft Internet Explorer") && (mouseEvent.which >1)) ||
((browserName=="Netscape")
{
rightClickPressed()
return false;
}
else
return true;
}
</script>
</head>
Then, in your body tag:
<body ondragstart="return false;" onselectstart="return false;" oncontextmenu="return false;">
--------------------------
What the above will do:
-Disable the Context Menu in IE4+ (Prevents the Menu Pop-up upon right-click).
-Disable right-click with an Alert in Netscape and some other browsers.
-Disable "Drag & Drop".
-Disable "Copy & Paste" by dumping cliboard data as soon as it's aquired.
-Disable Printscreen by dumping all data caught in the clipboard as soon as it's copied.
-Disable the ability to Select Text and/or Images(IE only).
Hope this helps you along your way.
Regards...
Note:
The body tag I gave above was incomplete, it should've been:
<body ondragstart="return false;" onselectstart="return false;" oncontextmenu="return false;" onload="clearData();">
I forgot the onload="clearData();" before which is the function needed to clear the clipboard each time something is copied.
Sorry if that caused any problems.
Regards...
That clears the clipboard if I browsed you site I would not be very happy,
To get all images put this in to the location bar press return (press Ctrl-n if no location bar first)
javascript:str='';for (i=0;i<document.images.len
Hey Gwyn, nifty code. Besides you and a few other Javascript Experts, who do you think would know that one?
You said "The vast majority of users are only moderately computer literate." - exactly.
"That clears the clipboard, if I browsed your site I would not be very happy" - The only reason one would be unhappy upon having their clipboard cleared in this situation would be if they were trying to copy your material or if they had previously copied some content from elsewhere. That would be the exact reason this is used. IMHO, if you are trying to copy protect your site, you are not trying to keep those who would copy it happy.
All together though, your comment above is the absolute answer to the question of copy protecting web pages/content:
"You can ultimately get everything".
Your address bar code and the fact that the above script I gave relies only on javascript being enabled shows that even if you protect your pages, there has not been a way developed to truly keep people from taking any content they want off of the Internet.
I imagine my script above could be coded in an "if" statement so that "window.clipboardData.setD
Regards...
Even if you did indeed manage to prevent all methods of extracting content via the browser, which is not likely, there is always the temporary internet file. So, to quote myself "if you don't want users to be able to save your files its best not too put them online".
While its true that the average Internet user will not be aware of the ways of getting around such protection there is still the big important factor of keeping your visitors happy. Removing the context menu is very annoying, replacing it with a JS alert even more so. The same applys to all methods that i have ever come across that serve the sole purpose of attempting to protect a sites content.
The only real protection that is out there is Copyright laws, although without a registered Copyright this can only do so much to protect your work. The best option, in the case of images, in my opinion is watermarking. While it cant stop users from downloading your image files it can protect the risk of others claiming your work as there own.
The question of hiding code and protecting images is discussed a lot here and the truth of he matter is you can not do. There are a multitude of ways of getting anything you want as it on your machine. You can make it more difficult for the average by disabling right click etc, (a very very common question here), but many users know about printscreen, you can disable it by clearing the clipboard (a bit tough in NS though) but if I had important info on the cliboard and coming to you site wipped it I would be really pissed off.
ps this gives the source , put in location bar hit return. :-)
javascript:document.write(
Hi :
Sorry for my late reply.
@GwynforWeb : I already checked your code and it shows numbers in pop up screen when click a key. Almost all keys shows numbers except print screen key which I really need. When I click on print screen, it doesn't show anything. If other key works then the print sceen should work, isn't it ? And I do not try your another comments where you mentioned "
==========================
To get all images put this in to the location bar press return (press Ctrl-n if no location bar first)
javascript:str='';for (i=0;i<document.images.len
==========================
Because I am not good in any scripting or any other languages. So, can you tell me where I have to put those code?
@Diablo84 : Yes, you are right that I would like to protect my original work which is mostly image. I understand that eveything is dragged out of the temp files folder but it is time consuming. So, I want to make some protection as much as I can. Atleast normal user (who are not pro.) cannot easily copy the graphics works.
@ziffgone: I tried your code too including the latest code :
<body ondragstart="return false;" onselectstart="return false;" oncontextmenu="return false;" onload="clearData();">
I find that it disable the right mouse click but I can still use the print screen and paste to paint or any other graphics software like photoshop. I think I am missing somewhere. I tried your code in offline (html) page. Do I need to be online?
--------------------------
*** Actually, I want a solution which can disable the print screen key.
rsdn
rsdn,
Did you use the corrisponding Javascript I provided. The -onload="clearData();"- relies on the clearData() function defined within the javascript code. It doesn't work in Netscape/Mozilla though, so if this is your browser, sorry, IE only. Unfortunately, I am not aware of how to clear clipboard data in Netscape.
To use Gwin's code, find a site with quite a few images, a gallery or something. While on that page, Copy and Paste Gwin's code into your browser's address bar. Click Go. The code extracts all images to a new page, regardless of what code you have incorporated to protect them.
To protect against your images being stored in Temp Cache, use this code:
<HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
Also, in order to fully protect it from caching in IE, add this again to the bottom of your HTML, like so:
</body>
<HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD>
</html>
A little warning though, using this will cause longer load times on your pages. If the viewer clicks to go to another page, then click Back on their browser, the images willl then cache anyway.
Regards...
Hi ziffgone:
I already do according to your instructions but I find that the screen print option is not yet disable. Here is the html page with a picture, you can take a look :
http://forums.metrobangla.
rsdn
Hi rsdn,
It seems I forgot to put a vital bit of code in there.
Change:
function clearData(){
window.clipboardData.setDa
}
To:
function clearData(){
window.clipboardData.setDa
}
function ccb(){
if(clipboardData){
clipboardData.clearData();
}
}
setInterval("ccb();", 1000);
Then change the "onload" in the <body> tag to: onload="ccb();"
That should do it.
Also add this to your <head> section:
<META HTTP-EQUIV="imagetoolbar" CONTENT="no">
This will disable IE6's image toolbar.
On the bottom of your page you gave as example, you had:
</body>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD>
It should be:
</body>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD>
</html>
Hope that helps.
Regards...
Hey Gang,
I know this post is closed...but I have an answer for disabling the "Print screen" button...sort of...since that was what "rsdn" was looking for...might help!
BTW...it was GywnForWeb that really inspired the solution with his/her comment of "...you would have to clear the clipboard periodically ...". And, of course, "ziffgone" really came up with the code...I just put the two together.
This is an extremely simple way to constantly clear the clipboard which (in my testing) does not appear to affect page performance. Very simply add ...
onmouseover= ="clearData();"
...to the body tag, based on the code created in "ziffgon"s original solution (you have to define the "clearData" function...see above), so the body tag reads ...
<body ondragstart="return false;" onselectstart="return false;" oncontextmenu="return false;" onload="clearData();" onmouseover="clearData();"
The affect of this will be that anytime the mouse moves anywhere over the page, the buffer will be cleared. Does this "technically" prevent the "Print screen?" No. But, if the user's mouse is anywhere over the web page when he/she hits the print screen, when he/she moves the mouse to go to the start button to start the app into which he/she will paste the image, he/she will activate the "onmouseover" command which will clear the buffer.
In other words, by the time the user starts the photo app to paste the image...the buffer will have been cleared. Will this work everytime...? No. BUT the ODDS are (I'm somewhat of a gambler) that this will work enough of the time to thwart 90% of attempts, and confuse even savvy inet users enough to give up before they figure it out (how many times would you hit the "print screen" and "paste" buttons over and over in the seemingly same manner thinking YOU are doing something wrong?)
Let me know if this works for you...or any of the likely flaws!!
Thanks!
M
Oop! Even better...change the "onmouseover" event to "onblur", I.E.
<body ondragstart="return false;" onselectstart="return false;" oncontextmenu="return false;" onload="clearData();" onblur="clearData();">
...so far, testing it with my own page, this has the effect of clearing the buffer as soon as the web page is no longer the top window. I.E. as soon as you start your "paste" app...the buffer is cleared.
Whoo hoo! I love cheating!
M
Nice solutions rightmirem, it's always fun to see another's take on a solution!
rightmirem, I would only use something like this if it is ABSOLUTELY imperative to you that you protect your work. If your content isn't really worth stealing, and you apply these measures, you will only succeed in sending your visitors elsewhere.
As with all web site protection using javascript, this one is completely useless if the user simply turns javascript off.
Also, Gwyn gave two examples on how to easily get the content from a web page:
http://www.experts-exchang
and:
http://www.experts-exchang
Anyway, have fun, eh?!
Regards...
All scripts place in here, not work in Mozilla...
I use a program to encrypt pages in asp, php, html, etc...and he's perfect to blocked all access inside the page. The only problem is other browsers, like Mozilla that not accept or understand the functions of JS...
Any solution for a code more "generic" ?
Thanks!!
Business Accounts
Answer for Membership
by: GwynforWebPosted on 2004-06-25 at 22:05:42ID: 11404154
The print key code can not be detected by a browser, it is considered to intrusive. Try the following to get the key codes and you will see that not all keys can be detected. (works in NS and IE). Basically no you can not disable it
getElement ById('txt' ))">
<script >
function setEvent(Id){
Id.onkeypress = function keyPress1(evt)
{
if (evt)
keyCode = evt.keyCode
else
keyCode = event.keyCode
alert(keyCode)
}
}
document.onkeydown = function keyPress(evt)
{
if (evt)
keyCode = evt.keyCode
else
keyCode = event.keyCode
alert(keyCode)
}
</script>
<body onload="setEvent(document.
Press a Key and get the Key code
</body>