W3cubDocs

/DOM

Clipboard.readText

The Clipboard interface's readText() method returns a Promise which resolves with a copy of the textual contents of the system clipboard.

Syntax

var promise = navigator.clipboard.readText()

Parameters

None.

Return value

A Promise that resolves with a DOMString containing the textual contents of the clipboard. Returns an empty string if the clipboard is empty, does not contain text, or does not include a textual representation among the DataTransfer objects representing the clipboard's contents.

To read non-text contents from the clipboard, use the read() method instead. You can write text to the clipboard using writeText().

Example

This example retrieves the textual contents of the clipboard and inserts the returned text into an element's contents.

navigator.clipboard.readText().then(
  clipText => document.getElementById("outbox").innerText = clipText);

Specifications

Specification Status Comment
Clipboard API and events
The definition of 'readText()' 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
Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
? 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
Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
53 ? ?

See also

© 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/readText