The Clipboard
interface's writeText()
property writes the specified text string to the system clipboard. Text may be read back using either read()
or readText()
.
The Clipboard
interface's writeText()
property writes the specified text string to the system clipboard. Text may be read back using either read()
or readText()
.
js
writeText(newClipText)
newClipText
The string 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.
Transient user activation is required. The user has to interact with the page or a UI element in order for this feature to work.
The "clipboard-write"
permission of the Permissions API is granted automatically to pages when they are in the active tab.
This example sets the clipboard's contents to the string "<empty clipboard>".
js
navigator.clipboard.writeText("<empty clipboard>").then( () => { /* clipboard successfully set */ }, () => { /* clipboard write failed */ }, );
Specification |
---|
Clipboard API and events # dom-clipboard-writetext |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
writeText |
66 | 79 | 63Writing to the clipboard is available without permission in secure contexts and browser extensions, but only from user-initiated event callbacks. Browser extensions with the"clipboardWrite" permission can write to the clipboard at any time. |
No | 53 | 13.1Must be called within user gesture event handlers such aspointerdown or pointerup . |
66 | 66 | 63Writing to the clipboard is available without permission in secure contexts and browser extensions, but only from user-initiated event callbacks. Browser extensions with the"clipboardWrite" permission can write to the clipboard at any time. |
47 | 13.4Must be called within user gesture event handlers such aspointerdown or pointerup . |
9.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText