The Clipboard API provides the ability to respond to clipboard commands (cut, copy, and paste) as well as to asynchronously read from and write to the system clipboard. Access to the contents of the clipboard is gated behind the Permissions API; without user permission, reading or altering the clipboard contents is not permitted.
This API is designed to supersede accessing the clipboard using document.execCommand()
Instead of creating a Clipboard
object through instantiation, you access the system clipboard through the Navigator.clipboard
global:
navigator.clipboard.readText().then( clipText => document.queryElementSelector(".editor").innerText += clipText);
This snippet fetches the text from the clipboard and appends it to the first element found with the class "editor"
. Since readText()
(and read()
, for that matter) returns an empty string if the clipboard isn't text, this code is safe.
Clipboard
Secure context
ClipboardEvent
Secure context
cut
, copy
, and paste
events. The specification refers to this as the 'Clipboard Event API'.Specification | Status | Comment |
---|---|---|
Clipboard API and events | Working Draft | Initial definition. |
Clipboard
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 66 | ? | 63 | ? | 53 | ? |
read |
No | ? | 63
|
? | No | ? |
readText |
66 | ? | 63
|
? | 53 | ? |
write |
No | ? | 63
|
? | No | ? |
writeText |
66 | ? | 63
|
? | 53 | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | No | 66 | ? | 63 | 53 | ? | ? |
read |
No | No | ? | 63
|
No | ? | ? |
readText |
No | 66 | ? | 63
|
53 | ? | ? |
write |
No | No | ? | 63
|
No | ? | ? |
writeText |
No | 66 | ? | 63
|
53 | ? | ? |
ClipboardEvent
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | Yes | Yes | Yes | 4 | Yes | Yes |
ClipboardEvent() constructor
|
58 | ? | Yes | ? | 45 | ? |
clipboardData
|
Yes | Yes | 22 | 5 | Yes | Yes |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
ClipboardEvent() constructor
|
58 | 58 | ? | Yes | 45 | ? | ? |
clipboardData
|
Yes | Yes | Yes | 22 | Yes | Yes | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API