-2

Wanted to create a script on my site that deletes everything in the clipboard every few milliseconds, for preventing screenshots, copying etc.

Here's what I've tried. Don't know why it isn't working. Please help.

<html>
<head>
<title>Testing a Script</title>
<script type="text/javascript">
function erase() {
    window.clipboardData.clearData();
    }
</script>
</head>
<body onload="setInterval(erase(),300);">
<center><br><br>
Hi, Copy this text and try to paste it.
</center>
</body>
</html>
braX
  • 11,506
  • 5
  • 20
  • 33
anuj.direct
  • 1
  • 1
  • 3
  • 1
    http://stackoverflow.com/questions/16748735/clear-clipboard-to-prohibit-unauthorised-copying-insert-message - You can't control clipboard with JavaScript – zedfoxus Oct 19 '15 at 18:55
  • @zedfoxus : Why not? I've seen that question and answer more than once. I have put some thought onto the matter and any method that clears the clipboard periodically will be of help to me, even if it doesn't solve the problem completely. If not javascript, what would you use? – anuj.direct Oct 19 '15 at 19:10
  • @TessellatingHeckler: Dude, this here is just a test sentence, when it comes to compicated code, the source code will make the average information pirate wonder what he's doing, the save-page as will only give him stuff that is badly formatted and missing details. the print to pDF can be disabled. Besides, my target market only needs detterence and I figured this would be good enough. – anuj.direct Oct 19 '15 at 19:13
  • 1
    Allowing access to JavaScript from Browser to OS system clipboard can pose security risks. That's why JavaScript doesn't help with controlling clipboard cross platform. [Flash/ActionScript](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/desktop/Clipboard.html#includeExamplesSummary) might help. – zedfoxus Oct 19 '15 at 19:27
  • 3
    @anuj.direct It would also be "good enough" to fill the user's hard disk with random numbers so there was no space to save anything, and then disable any communication with any other computer. It's user hostile. The clipboard is a tool for the user, used system wide, it's not just for stealing from paranoid websites. You can't just delete someone else's clipboard unilaterally *even if it was effective* (which it's not very). It's awful behavior for a program or site. – TessellatingHeckler Oct 19 '15 at 19:28
  • Also remember that a person could install a software such as http://www.debugmode.com/wink/ or similar that can take screenshots and stream them to disk every few seconds. – zedfoxus Oct 19 '15 at 19:32
  • @TessellatingHeckler: It's also not good to screenshot a website that clearly prohibits copying and disables the usual copying facility. If someone needs info and it's give-able, I can give a download and you don't have to worry about copying. Yes, user needs are a prioroty and I know how to take care of them. If you're screenshoting even after that, it's done by folks who now want to go out of the way to steal...that's the psyche behind all the wise ways invented to copy/rip-off sites. – anuj.direct Oct 19 '15 at 19:41
  • @TessellatingHeckler: Now, instead of arguing with you, if I can ask a reasonable solution from a professional person, I'd be done and we can stop sparring. My idea is not to bug users, they get the info they need, I have provisions for that. The idea is simply to prohibit and deter copying of info that I HAVE TO make visible publicly (no other option), so people can see it, evaluate certain parts and get in touch, without ripping it off, or modifying it and using it as their own. – anuj.direct Oct 19 '15 at 19:42
  • @zedfoxus: Yes, I know. My target user-base isn't into that kinda stuff so much. So custom screencapturing is a small problem and I'm willing to risk it. Do you have a solution to help with my code? I mean if JavaScript is a problem and vulnerability, how would you work around it? – anuj.direct Oct 19 '15 at 19:43
  • I have a recommendation that you try [Flash/ActionScript](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/desktop/Clipboard.html#includeExamplesSummary) to clear clipboard or you should [try doing what Trello does](http://stackoverflow.com/questions/17527870/how-does-trello-access-the-users-clipboard) to overwrite clipboard content with empty space – zedfoxus Oct 19 '15 at 19:48
  • @zedfoxus: Thanks for suggesting trello...and I believe, their textarea overwrite method will act on the Ctrl key. Can you help me extend this to the PrintScreen key as well? – anuj.direct Oct 19 '15 at 20:03
  • I don't think you can do much with PrintScreen. Check http://stackoverflow.com/questions/3130983/stop-user-from-using-print-scrn-printscreen-key-of-the-keyboard-for-any-we and http://stackoverflow.com/questions/10577515/how-to-capture-printscreen-event-in-javascript and http://www.codeproject.com/Questions/185081/Stop-print-Screen-for-all-web-browser – zedfoxus Oct 19 '15 at 20:06
  • @zedfocus: Hah! It gave me a li'l laugh. Thanks! – anuj.direct Oct 19 '15 at 20:27
  • @zedfoxus: I read the links and saw that Flash and ActiveX tend to get blocked away automatically and clipboards are being taken out of the reach of JavaScript...... so then how would you prevent the simple screenshot (non video, non wink) from getting pasted? – anuj.direct Oct 19 '15 at 21:16
  • If you are asking what I prefer to do, the answer is I wouldn't go to lengths to prevent user from screenshoting or copying information from an accessible page. If it was a quiz, I'd make it intellectually stimulating and shuffle some questions. Other than that, let users copy/photograph/print-to-pdf/screenshot/whatever. There is legal paperwork to protect intellectual property, where applicable and honored. – zedfoxus Oct 19 '15 at 21:35
  • 1
    @anuj.direct There isn't a reasonable solution. That doesn't make an unreasonable one OK. [There's no programmatic access to the start page](http://blogs.msdn.com/b/oldnewthing/archive/2014/10/29/10568120.aspx) or [the quicklaunch](http://blogs.msdn.com/b/oldnewthing/archive/2009/02/02/9388941.aspx). If [every program deleted the clipboard on a timer](http://blogs.msdn.com/b/oldnewthing/archive/2005/06/07/426294.aspx), it would be ruined. If it's important, don't put it online. If you HAVE TO put it online then you HAVE TO accept that the viewing software is not your place to exert control. – TessellatingHeckler Oct 19 '15 at 21:43
  • @zedfoxus: Thanks for attempting to solve this. – anuj.direct Oct 20 '15 at 05:45
  • If it's so sensitive that it can't be copied or saved, then don't let someone access it via a URL. I could write my own Evil Browser which pretends to be Chrome, but ignores all attempts to clear clipboard or prevent saving or screenshots, and then what will you do? – Ky - Dec 19 '18 at 21:11

2 Answers2

2

This would erase clipboard data when the user tries to, however you cannot disable screenshots. You also can't avoid the user clicking "inspect element" and digging through the HTML.

document.addEventListener('copy', function (evt) {
  evt.clipboardData.setData('');
});

As a bit more...extreme measure you could try:

document.addEventListener('copy', function() { alert("No copying!"); });
Robert Moore
  • 2,207
  • 4
  • 22
  • 41
1

How about trying to disable right click on your website?

Even then it's not too hard to copy the information from your website, you could still use a snipping tool, screen recorder, etc.

cucumber_boy
  • 173
  • 1
  • 12
  • Yes, I already have right-click disabled. The key is to make it tedious enough to copy so that the person on the other end thinks - "If I'm going to waste that much time on it, I might as well make an original". Thanks for the prompt response. – anuj.direct Oct 19 '15 at 18:58
  • What would the code be for clearing the clipboard on the user's machine who is viewing the site, irrespective of whether the browser / tab is active or the taskbar? – anuj.direct Oct 19 '15 at 18:58
  • @anuj.direct What if I made my own browser that always allows right-click and copy, no matter what script you write? And that browser shows up as Chrome so you can't block against it? – Ky - Dec 19 '18 at 21:12