I
I
Ivan Sergeevich2014-09-13 23:25:48
JavaScript
Ivan Sergeevich, 2014-09-13 23:25:48

How to clear clipboard, javascript?

Dear colleagues, is it possible to clear the buffer using javascript when copying content from the site into it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sn0wSky, 2014-09-14
@Sn0wSky

Clear clipboard - nothing. Prohibit copying - possible, but not 100%.

A
AXLLLOW, 2019-06-11
@AXLLLOW

The solution consists of two stages.
1. Copying to the clipboard is done like this : document.execCommand('copy')
* but the important condition is that you can copy the text selected by the user.
Therefore, the function of copying text to the clipboard looks like this:
var copyToClipboard = function (text) {
var $txt = $ ('');
$txt.val(text).css({ width: "1px", height: "1px" }).appendTo('body');
$txt.select();
if (document.execCommand('copy')) {
$txt.remove();
}
};
Since copyToClipboard(""); and copyToClipboard(''); - will not copy the void to the buffer.
A space is not empty. Gotta find the void
Word connector symbol (U+2060)
And we throw it as an argument to the copyToClipboard("⁠");
* Perhaps if you copy the code from the court - it will not work. Therefore, I advise you to manually write everything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question