The Clipboard interface implements the Clipboard API, providing—if the user grants permission—both read and write access to the contents of the system clipboard. The Clipboard API can be used to implement cut, copy, and paste features within a web application.
The system clipboard is exposed through the global Navigator.clipboard property.
Calls to the methods of the Clipboard object will not succeed if the user hasn't granted the needed permissions using the Permissions API and the "clipboard-read" or "clipboard-write" permission as appropriate.
Note: In reality, at this time browser requirements for access to the clipboard vary significantly. Please see the section Clipboard availability for details.
All of the Clipboard API methods operate asynchronously; they return a Promise which is resolved once the clipboard access has been completed. The promise is rejected if clipboard access is denied.
Clipboard is based on the EventTarget interface, and includes its methods.
read()Promise. When the data has been retrieved, the promise is resolved with a DataTransfer object that provides the data.readText()Promise which is resolved with a DOMString containing the clipboard's text once it's available.write()Promise.writeText()Promise which is resolved once the text is fully copied into the clipboard.The asynchronous clipboard API is a relatively recent addition, and the process of implementing it in browsers is not yet complete. Due to both potential security concerns and technical complexities, the process of integrating this API is happening gradually in most browsers.
For example, Firefox does not yet support the "clipboard-read" and "clipboard-write" permissions, so access to the methods that access and change the contents of the clipboard are restricted in other ways. In addition, read() and write() are disabled by default and require changing a preference to enable them. Check the compatibility tables for each method before using it.
| Specification | Status | Comment |
|---|---|---|
| Clipboard API and events The definition of 'Clipboard' in that specification. | Working Draft | Initial definition. |
| 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 | ? | ? |
© 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