The Clipboard
interface's writeText()
property writes the specified text string to the system clipboard.
Note: The specification requires the Permissions API be used to obtain the "clipboardWrite"
permission before writing to the clipboard. However, exact requirements vary from browser to browser, since this is a new API. Check the compatibility table and Clipboard availability in Clipboard for details.
var promise = navigator.clipboard.writeText(newClipText)
newClipText
DOMString
to be written to the clipboard.A Promise
which is resolved once the clipboard's contents have been updated. The promise is rejected if the caller does not have permission to write to the clipboard.
This example sets the clipboard's contents to the string "<empty clipboard>".
navigator.clipboard.writeText("<empty clipboard>").then(function() { /* clipboard successfully set */ }, function() { /* clipboard write failed */ });
Specification | Status | Comment |
---|---|---|
Clipboard API and events The definition of 'writeText()' in that specification. | Working Draft | Initial definition. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 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 | ? | ? |
© 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/writeText