Clipboard 接口的 readText() 方法返回 Promise which resolves with a copy of the textual contents of the system clipboard. "clipboard-read" permission of the 权限 API must be granted before you can read data from the clipboard.

句法

var promise = navigator.clipboard.readText()
					

参数

None.

返回值

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() .

范例

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);
					

规范

规范 状态 注释
Clipboard API and events
The definition of 'readText()' in that specification.
工作草案 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
readText Chrome 66 Edge 79 Firefox 63
63
Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
IE No Opera 53 Safari 13.1 WebView Android 66 Chrome Android 66 Firefox Android 63
63
Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
Opera Android 47 Safari iOS 13.4 Samsung Internet Android 9.0

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: