Clipboard
接口的
writeText()
property writes the specified text string to the system clipboard. Text may be read back using either
read()
or
readText()
.
"clipboard-write"
permission of the
权限 API
, is granted automatically to pages when they are in the active tab.
注意: Browser support for the asynchronous clipboard APIs is still in the process of being implemented. Be sure to check the 兼容性表格 及 Clipboard availability in Clipboard 了解更多信息。
var promise = navigator.clipboard.writeText(newClipText)
newClipText
DOMString
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.
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 */
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
Clipboard API and events
The definition of 'writeText()' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
writeText
|
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
read()
readText()
write()
writeText()