Re: JavaScript, Print Screen & Windows Clipboard



toronto@xxxxxxxx said the following on 12/24/2007 11:51 PM:
Seasons Greetings Everyone!

I want to use JavaScript's event object to detect whether someone has
pressed the 'PrintScreen' key to screenshot, via the Windows Clipboard,
and to print website content I don't want printed...

If you don't want it printed, log on to your server, delete the files. Then it can't be printed. Anything else is a futile waste of time.

It occurred to me that the easiest way to do this is to erase or replace
the contents of the Windows Clipboard...

Providing that you can dictate that your website users are using IE, they have script enabled, and they have allowed you programmatic access to the clipboard.

IE7:

Tools>Internet Options>Security Tab>Custom Level>Allow Programmatic clipboard access

Some code snippets I found at webdeveloper.com forums:

onfocus="javascript:window.clipboardData.clearData()"

This way their clipboard is emptied before they have he chance to paste.

No it isn't. Size your page smaller than the windows desktop, focus on anything other than the website, print screen, go to graphics program, paste it.

<!--Msg in span-->
<span id="copytext" style="display:none;">
You have mistakenly attempted to use the Print Scrn SysRq button or tried to copy something, which is a no-no. Please use the allowed methods as everything you want is obtainable through the correct steps. thank you, -site admin
</span>
<textarea id="holdtext" style="display:none;">
</textarea>
<script>function ClipBoard() {
holdtext.innerText = copytext.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");
setTimeout("ClipBoard()", 0001); }
ClipBoard();</script>

Open your page in IE.
Open a second IE.
Disable scripting.
Copy all you want.

Or, use any non-IE browser and copy what you want.

Clear your cache. Open the page. Go to the cache, copy what you want.

or u can diable highlight!!!!

No, you can try.

Since a lot of examples like this tend to deal with forms and/or
mouse text selection, can anyone explain what this code does, and
if I'm on the right track...? Thanks.

What it attempts to do is copy text to the clipboard - constantly - in a failed attempt to stop copy/paste actions. And no, you are not even close to being on the right track.

If you don't want it copied, printed, saved, don't let people view it.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
.



Relevant Pages

  • Re: Meaning of keyboard keys
    ... Pressing the key copies the entire display to the ... the clipboard. ... paste the contents of the clipboard (your screenshot) into the open ... How to Capture Screen Shots in Windows Using the Print Screen Key ...
    (microsoft.public.windowsxp.hardware)
  • Re: Print screen button does not work
    ... MS-MVP Windows Shell/User ... entire screen like the normal screenshot function. ... This will clear out *everything* from the System Clipboard. ...
    (microsoft.public.windowsxp.general)
  • Re: Print Screen doesnt work
    ... By design, as it has always been with every version of Windows, pressing the key copies the entire display, including the Desktop Wallpaper, to the clipboard. ... This will paste the contents of the clipboard (your screenshot) into the open file, and allow you to view it or save it as a file for later use. ... The philosopher has never killed any priests, whereas the priest has killed a great many philosophers. ...
    (microsoft.public.windowsxp.basics)
  • Re: Print screen button does not work
    ... I have the same Windows as you, and it handles the PrintScreen function ... with XP service pack 1, ... entire screen like the normal screenshot function. ... This will clear out *everything* from the System Clipboard. ...
    (microsoft.public.windowsxp.general)
  • Novell Client login form enables reading and writing from and to the clipboard of the logged-in
    ... Novell Client for Windows, ... Anyone with access to the computer's local operating system console, ... inject its own textual content into the clipboard of the currently logged-in ...
    (Bugtraq)