Clipboard.readText()

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

See also