Clipboard.readText() - Web API 接口参考 编辑
Clipboard
接口的readText()
方法解析系统剪贴板的文本内容返回一个Promise
。语法
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.
要从剪贴板中读取非文本内容,请改用read()
方法。您可以使用 writeText()
将文本写入剪贴板
例子
此示例检索剪贴板的文本内容,并将返回的文本插入元素的内容中。
navigator.clipboard.readText().then(
clipText => document.getElementById("outbox").innerText = clipText);
规范
规范 | 状态 | 注解 |
---|---|---|
Clipboard API and events readText() | Working Draft | Initial definition. |
浏览器兼容性
BCD tables only load in the browser
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.See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论