最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Illegal constructor in chrome when using clipboard API? - Stack Overflow

programmeradmin4浏览0评论

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 tells me I should be able to use the 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./#feat=clipboard tells me I should be able to use the clipboard API?

Share asked May 24, 2015 at 0:50 TylerTyler 3323 silver badges17 bronze badges 4
  • I don't think you need the document.dispatchEvent(magicevent);. Try removing it. – Ismael Miguel Commented May 24, 2015 at 0:58
  • Still get "Uncaught TypeError: Illegal constructor" :( – Tyler Commented May 24, 2015 at 1:00
  • Sorry the delay to say something. You should check this: stackoverflow./questions/28861479/… – Ismael Miguel Commented May 24, 2015 at 1:42
  • my problem was that Clipboard library was not included on the page – lsimonetti Commented Aug 26, 2019 at 21:35
Add a ment  | 

2 Answers 2

Reset to default 4

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/yongqing_/article/details/88605841

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

发布评论

评论列表(0)

  1. 暂无评论