Question

So as has been encountered/asked before I'm trying to make a copy function that works on non-flash devices.

This has led me to the Clipboard API.
But I can't seem to get it working properly, this is what I have so far:

$(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 quite self-explanatory, on a click of the button it should copy "This has been copied" to the clipboard. Upon trying to do so I get:
"Uncaught ReferenceError: ClipboardEvent is not defined". What am I missing? Shouldn't this be "built in" or is there a need to call the API in anyway?
Also stumbled upon this which gives the same error.

This seems to be a simple misstake, or is the API currently not working?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top