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. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
readText
|
Chrome 66 | Edge 79 |
Firefox
63
|
IE No | Opera 53 | Safari 13.1 | WebView Android 66 | Chrome Android 66 |
Firefox Android
63
|
Opera Android 47 | Safari iOS 13.4 | Samsung Internet Android 9.0 |
完整支持
不支持
见实现注意事项。
Clipboard.writeText()
Clipboard.write()
Clipboard
read()
readText()
write()
writeText()