Clipboard.writeText() - Web APIs 编辑
The Clipboard
interface's writeText()
property writes the specified text string to the system clipboard. Text may be read back using either read()
or readText()
.
The "clipboard-write"
permission of the Permissions API, is granted automatically to pages when they are in the active tab.
Note: Browser support for the asynchronous clipboard APIs is still in the process of being implemented. Be sure to check the compatibility table as well as Clipboard availability in Clipboard for more information.
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 compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论