Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal constructor in chrome when using clipboard API?

I'm currently building a web application that is a translation of another program I wrote in visual basic long ago. In visual basic there was the ability to put data directly into the operating system's clipboard. Is there functionality to do this in chrome? I've tried:

var magicevent = new ClipboardEvent('copy', { dataType: 'text/plain', data: 'Data to be copied' } );
document.dispatchEvent(magicevent);

however Chrome gives me and Illegal constructor error, while http://caniuse.com/#feat=clipboard tells me I should be able to use the clipboard API?

like image 746
Tyler Avatar asked Nov 06 '25 06:11

Tyler


2 Answers

I have searched a lot for a solution, since this is the first time using this lib. However thanks to our lovely chinese friends, they pointed out the solution for this error.

Solution: clipboard.js has been tweaked and can use global ClipboardJS to prevent conflicts. Such as:

var clipboard = new ClipboardJS('#btn');

https://blog.csdn.net/yongqing_/article/details/88605841

like image 168
Mecanik Avatar answered Nov 08 '25 03:11

Mecanik


The ClipboardEvent constructor cannot be instantiated in Chrome as of version 51. See the relevant caniuse page for details, and make sure to read the functional notes.

More specifically:

Does not support the ClipboardEvent constructor

like image 44
grill Avatar answered Nov 08 '25 01:11

grill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!