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?
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?
Share Improve this question edited May 23, 2017 at 11:50 CommunityBot 11 silver badge asked Apr 23, 2014 at 7:56 SeloSelo 2501 gold badge3 silver badges10 bronze badges 3- With which browser you're trying to do it? – Adriano Repetti Commented Apr 23, 2014 at 7:59
- I've tried with IE 10 and Chrome v34, but end goal is getting it to work on mobile browsers – Selo Commented Apr 23, 2014 at 8:03
-
@user3088863: Neither of those supports the
ClipboardEvent
constructor. – T.J. Crowder Commented Apr 23, 2014 at 8:03
1 Answer
Reset to default 2To date, only Firefox supports the ClipboardEvent
constructor; support info.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745330724a4622865.html
评论列表(0条)