
When implemented, navigator.clipboard will let you write code like this: ('Text to be copied') Async Clipboard API will provide a simpler way to manage the clipboard If the "copy" handler was triggered, the focus will move to the textbox below automatically, so that you can try pasting from clipboard: Try selecting this text and triggering a copy usingĭocument.execCommand('copy') - should work.ĭocument.dispatchEvent(clipboardEvent) - should NOT work Note that you need to prevent the default action in the event handler to prevent your changes from being overwritten by the browser: document.addEventListener('copy', function(e))


Clipboard APIs were indeed in active development as of 2016, but things have stabilized since then: Using () is supportedĬhanging the clipboard with () inside a 'copy' event handler is allowed by the spec (as long as the event is not synthetic).
