Clear clipboard to prohibit unauthorised copying, insert message?

后端 未结 3 682
不知归路
不知归路 2020-12-12 01:55

Is it possible to write your own message into the clipboard when copying website data using ctrl+c? I\'ve found some Javascript that clears the clipboard - would be interest

相关标签:
3条回答
  • 2020-12-12 02:35

    Yes, you can. The basic trick is that you detect when a user holds down Control, and select a different piece of text on the page.

    0 讨论(0)
  • 2020-12-12 02:54

    You could place the following:

    $( document ).ready(function() {
        if (event.ctrlKey && event.keyCode == 67) {
            var inputFieldClear = document.createElement("input");
            inputFieldClear.setAttribute("value", "Insert Default Value Here");
            document.body.appendChild(inputFieldClear);
            inputFieldClear.select();
            document.execCommand('copy');
            inputFieldClear.remove();
            console.log("Attempting to Alter Clipboard")
    }});
    

    That would work in something like TamperMonkey - not sure if it could be incorporated into the sites source or not.

    Hope it helps! :)

    0 讨论(0)
  • 2020-12-12 02:56

    You can't do it purely through JavaScript.

    JavaScript editing of the clipboard is considered a security vulnerability (and there is much more discussion on this).

    You could do it through hacks that uses Flash for clipboard access interacting with JavaScript.

    0 讨论(0)
提交回复
热议问题