admin管理员组文章数量:1410697
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
2 Answers
Reset to default 4I 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
本文标签: javascriptIllegal constructor in chrome when using clipboard APIStack Overflow
版权声明:本文标题:javascript - Illegal constructor in chrome when using clipboard API? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744884444a2630405.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论