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.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
readTextChrome Full support 66Edge No support NoFirefox Full support 63
Notes
Full support 63
Notes
Notes Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
IE No support NoOpera Full support 53Safari No support NoWebView Android Full support 66Chrome Android Full support 66Firefox Android Full support 63
Notes
Full support 63
Notes
Notes Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
Opera Android Full support 47Safari iOS No support NoSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

See also