Using Clipboard API - Throw Error "Not Set"

So, as it was met / asked before I am trying to create a copy function that works on non-flash devices.

This led me to the clipboard API .
But I can not get it to work fine, this is what I still have:

$(function () {
    $(document).on( 'click', '.copy-btn', function (e) {
        var data = 'This has been copied';

        var clip = new ClipboardEvent( 'copy' );
        clip.clipboardData.setData( 'text/plain', data );
        clip.preventDefault();

        e.target.dispatchEvent( clip );
    });
});

The code is clear enough, at the click of a button it should copy “This was copied” to the clipboard. Trying to do this I get:
"Uncaught ReferenceError: ClipboardEvent not defined." What am I missing? Shouldn't it be "embedded" or is there a need to call the API anyway?
Also came across this , which gives the same error.

Does this seem like a simple failure, or is the API currently not working?

+4
source share
1 answer

To date, only Firefox supports the constructor ClipboardEvent; support information .

+2
source

Source: https://habr.com/ru/post/1537645/


All Articles