W3cubDocs

/DOM

Clipboard.writeText

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.

Syntax

var promise = navigator.clipboard.writeText(newClipText)

Parameters

newClipText
The DOMString to be written to the clipboard.

Return value

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.

Example

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 */
});

Specifications

Specification Status Comment
Clipboard API and events
The definition of 'writeText()' in that specification.
Working Draft Initial definition.

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 66 ? 63
63
Writing 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.
? 53 ?
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support No 66 ? 63
63
Writing 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.
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