Is it possible to create instance of ClipboardEven

2019-03-14 19:46发布

I need to programmatically create a ClipboardEvent instance in Chrome.

But when I run the constructor:

new ClipboardEvent("paste", {dataType: "text/plain", data: "some data"})

It throws the following error:

Uncaught TypeError: Illegal constructor

The constructor works as intended in Firefox.

Checked MDN and W3C spec and they don't mention anything about it being illegal to create instances of ClipboardEvent.

Is it possible to create an instance of ClipboardEvent in Chrome in any other way? I prefer to not mock a custom ClipboardEvent when one exists.

Update 2018-07-17: Using the ClipboardEvent seems to work in Chrome 69.

1条回答
smile是对你的礼貌
2楼-- · 2019-03-14 20:21

Unfortunately, it's not. This is from http://caniuse.com/#feat=clipboard

Partial support in IE refers using a non-standard method of interacting with the clipboard. For other browsers it refers to not supporting the ClipboardEvent constructor.

enter image description here

Unfortunately, the only browser that properly supports the Clipboard API is FireFox (since 22). All other browsers (if it supports Clipboard API at all), will not support the ClipbordEvent constructor.

查看更多
登录 后发表回答