Question

Disable print screen in keyboard

Asked by: rsdn

Hi:

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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-06-25 at 21:54:28ID21038839
Tags

print

,

screen

,

disable

Topic

JavaScript

Participating Experts
5
Points
500
Comments
24

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Disabling printscreen
    Can anyone show me how to disable the print screen event. There are two ways I guess, either through Application.OnMessage or through theWMSysCommand(var message... I'd like the second since the first would slow the application down. Please anyone!
  2. Block the PrintScreen (CaptureScreen)
    I would like to generate a black screen everytime someone try to do a printscreen (CaptureScreen) . Or, If more simple, only block the printscreen. Any comment will be helpful. Thanks, emu10k1.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

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

<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.getElementById('txt'))">
Press a Key and get the Key code
</body>

 

by: GwynforWebPosted on 2004-06-25 at 22:07:01ID: 11404157

shld read "The printscreen key code...."

 

by: rsdnPosted on 2004-06-25 at 22:23:05ID: 11404174

Hi GwynforWeb:

Thanks for your reply. I will check it when I go back to my room. I will let you know.

rsdn

 

by: GwynforWebPosted on 2004-06-25 at 22:53:56ID: 11404238

warning:- the above will not run in FrontPage (possibly dreamweaver as well)  it must go into a browser.

 

by: Diablo84Posted on 2004-06-26 at 16:19:29ID: 11407808

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

 

by: GwynforWebPosted on 2004-06-26 at 19:30:34ID: 11408315

  You can ultimately get everything, but you can make it sufficiently difficult to stop a large number of users. The vast majority of users are only moderately computer literate.  With images the ultimate down fall is of course print screen for which there is no antidote at all.

 

by: ziffgonePosted on 2004-06-26 at 20:47:26ID: 11408500

Paste this into the head of your page:

<head>
<script language="javascript">
<!--
function clearData(){
window.clipboardData.setData('text','')
}
browserName         = navigator.appName
browserVersion      = parseInt(navigator.appVersion)

document.onmousedown = checkforRightMouseButtonClick;
if (browserVersion<5 && browserName=="Netscape")
  {
    window.onmousedown = checkforRightMouseButtonClick;
  }

function rightClickPressed()
{
   alert("For Security reasons, Right-click has\nbeen disabled for this Web Page\n\nSorry for any inconvenience.");
}

function checkforRightMouseButtonClick(mouseEvent)
{
  if ( ((browserName != "Microsoft Internet Explorer") && (mouseEvent.which >1)) ||
       ((browserName=="Netscape") && (mouseEvent.which > 1)) )
    {
      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...

 

by: ziffgonePosted on 2004-06-27 at 09:08:27ID: 11410585

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

 

by: GwynforWebPosted on 2004-06-27 at 09:16:26ID: 11410599

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.length;i++){str+='<img src='+document.images[i].src+'>'+document.images[i].src+'<P>'}document.write(str)

 

by: ziffgonePosted on 2004-06-27 at 10:26:43ID: 11410805

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.setData('text','')" is only used if new clipboard data is detected, instead of automatically clearing the clipboard onload.

Regards...


 

by: Diablo84Posted on 2004-06-27 at 13:10:38ID: 11411400

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.

 

by: Diablo84Posted on 2004-06-27 at 13:13:32ID: 11411424

apologies to rsdn for drawing away from the original question slightly, i find this to be an interesting topic though

 

by: GwynforWebPosted on 2004-06-27 at 13:50:26ID: 11411585

  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('<textarea cols=120 rows=50>'+document.body.parentNode.innerHTML+'<\textarea>')

 

by: GwynforWebPosted on 2004-06-27 at 13:55:20ID: 11411606

...you can copy the clipbaord and replace it onunload but gets very messy (if  not impossible) if there is not text on there.

 

by: GwynforWebPosted on 2004-06-27 at 14:01:03ID: 11411628

...the other point that is as I said before certain key presses are not detected at all PrintScreen is one of them. So you would have to clear the clipboard periodically using setInterval(), and resetting on onblur() and and onload() and clearing onload and onfocus()  (uggh)

 

by: rsdnPosted on 2004-06-30 at 15:02:55ID: 11441458

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.length;i++){str+='<img src='+document.images[i].src+'>'+document.images[i].src+'<P>'}document.write(str)
===============================================

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
 




 

by: ziffgonePosted on 2004-07-01 at 05:09:21ID: 11445734

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

 

by: rsdnPosted on 2004-07-04 at 19:36:55ID: 11470414

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.com/temp/

rsdn

 

by: ziffgonePosted on 2004-07-04 at 20:31:18ID: 11470533

Hi rsdn,

It seems I forgot to put a vital bit of code in there.

Change:

function clearData(){
window.clipboardData.setData('text','')
}

To:

function clearData(){
window.clipboardData.setData('text','')
}
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...

 

by: rsdnPosted on 2004-07-05 at 12:59:28ID: 11475566

Hi ziffgone:

Excellent work ! Now it is working perfect. I increase points from 250 to 500 and I think
GwynforWeb deserve some points for his code.

Thank you very much for your help.

rsdn

 

by: rightmiremPosted on 2004-08-09 at 17:26:48ID: 11758614

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

 

by: rightmiremPosted on 2004-08-09 at 17:39:36ID: 11758678

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


 

by: ziffgonePosted on 2004-08-10 at 08:18:24ID: 11763787

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-exchange.com/Web/Web_Languages/JavaScript/Q_21038839.html#11410599

and:

http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21038839.html#11411585

Anyway, have fun, eh?!

Regards...

 

by: FloydivisionPosted on 2004-09-11 at 11:46:39ID: 12035355

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

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...