Clipboard API provides the ability to respond to clipboard commands (cut, copy, and paste) as well as to asynchronously read from and write to the system clipboard. Access to the contents of the clipboard is gated behind the 权限 API : The clipboard-write permission is granted automatically to pages when they are in the active tab. The clipboard-read permission must be requested, which you can do by trying to read data from the clipboard.

This API is designed to supersede accessing the clipboard using document.execCommand() .

Accessing the clipboard

Instead of creating a Clipboard object through instantiation, you access the system clipboard through the Navigator.clipboard global:

navigator.clipboard.readText().then(
  clipText => document.querySelector(".editor").innerText += clipText);
					

This snippet fetches the text from the clipboard and appends it to the first element found with the class editor 。由于 readText() (和 read() , for that matter) returns an empty string if the clipboard isn't text, this code is safe.

接口

Clipboard 安全上下文

Provides an interface for reading and writing text and data to or from the system clipboard. The specification refers to this as the 'Async Clipboard API.'

ClipboardEvent 安全上下文
Represents events providing information related to modification of the clipboard, that is cut , copy ,和 paste events. The specification refers to this as the 'Clipboard Event API'.
ClipboardItem 安全上下文

Represents a single item format, used when reading or writing data.

规范

规范 状态 注释
Clipboard API and events 工作草案 初始定义。

浏览器兼容性

Clipboard

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Clipboard 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
read Chrome 部分支持 76 注意事项
部分支持 76 注意事项
From version 76, the image/png MIME type is supported.
部分支持 66 注意事项
Images are not supported.
Edge 79 Firefox 63 注意事项 Disabled
63 注意事项 Disabled
Currently works just like readText() ; non-text content is not currently supported.
Disabled ). To change preferences in Firefox, visit about:config.
IE 不支持 No Opera 63 Safari 13.1 WebView Android 部分支持 84 注意事项
部分支持 84 注意事项
From version 84, the image/png MIME type is supported.
部分支持 66 注意事项
Images are not supported.
Chrome Android 部分支持 84 注意事项
部分支持 84 注意事项
From version 84, the image/png MIME type is supported.
部分支持 66 注意事项
Images are not supported.
Firefox Android 63 注意事项 Disabled
63 注意事项 Disabled
Currently works just like readText() ; non-text content is not currently supported.
Disabled ). To change preferences in Firefox, visit about:config.
Opera Android 54 Safari iOS 13.4 Samsung Internet Android 12.0
readText Chrome 66 Edge 79 Firefox 63 注意事项
63 注意事项
Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
IE 不支持 No Opera 53 Safari 13.1 WebView Android 66 Chrome Android 66 Firefox Android 63 注意事项
63 注意事项
Firefox only supports reading the clipboard in browser extensions, using the "clipboardRead" extension permission.
Opera Android 47 Safari iOS 13.4 Samsung Internet Android 9.0
write Chrome 66 注意事项
66 注意事项
From version 76, the image/png MIME type is supported.
Edge 79 Firefox 63 注意事项 Disabled
63 注意事项 Disabled
Currently works exactly like writeText() , including the availability limitations currently imposed by Firefox.
Disabled ). To change preferences in Firefox, visit about:config.
IE 不支持 No Opera 63 Safari 13.1 WebView Android 66 注意事项
66 注意事项
From version 84, the image/png MIME type is supported.
Chrome Android 66 注意事项
66 注意事项
From version 84, the image/png MIME type is supported.
Firefox Android 63 注意事项 Disabled
63 注意事项 Disabled
Currently works exactly like writeText() , including the availability limitations currently imposed by Firefox.
Disabled ). To change preferences in Firefox, visit about:config.
Opera Android 54 Safari iOS 13.4 Samsung Internet Android 12.0
writeText Chrome 66 Edge 79 Firefox 63 注意事项
63 注意事项
Writing to the clipboard is available without permission in secure contexts and browser extensions, but only from user-initiated event callbacks. Browser extensions with the "clipboardWrite" permission can write to the clipboard at any time.
IE 不支持 No Opera 53 Safari 13.1 WebView Android 66 Chrome Android 66 Firefox Android 63 注意事项
63 注意事项
Writing to the clipboard is available without permission in secure contexts and browser extensions, but only from user-initiated event callbacks. Browser extensions with the "clipboardWrite" permission can write to the clipboard at any time.
Opera Android 47 Safari iOS 13.4 Samsung Internet Android 9.0

图例

完整支持

完整支持

部分支持

部分支持

不支持

不支持

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

ClipboardEvent

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
ClipboardEvent Chrome Yes Edge 12 Firefox 22 IE 4 Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 22 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
ClipboardEvent() 构造函数 Chrome 58 Edge ≤79 Firefox 22 IE ? Opera 45 Safari ? WebView Android 58 Chrome Android 58 Firefox Android 22 Opera Android 43 Safari iOS ? Samsung Internet Android 7.0
clipboardData Chrome Yes Edge 12 Firefox 22 IE 5 Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 22 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

ClipboardItem

The compatibility table in 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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
ClipboardItem Chrome 66 Edge ≤79 Firefox 不支持 No IE 不支持 No Opera Yes Safari 不支持 No WebView Android 66 Chrome Android 66 Firefox Android 不支持 No Opera Android Yes Safari iOS 不支持 No Samsung Internet Android Yes
ClipboardItem() 构造函数 Chrome 66 Edge ≤79 Firefox 不支持 No IE 不支持 No Opera Yes Safari 不支持 No WebView Android 66 Chrome Android 66 Firefox Android 不支持 No Opera Android Yes Safari iOS 不支持 No Samsung Internet Android Yes
getType Chrome 66 Edge ≤79 Firefox 不支持 No IE 不支持 No Opera Yes Safari 不支持 No WebView Android 66 Chrome Android 66 Firefox Android 不支持 No Opera Android Yes Safari iOS 不支持 No Samsung Internet Android Yes
类型 Chrome 66 Edge ≤79 Firefox 不支持 No IE 不支持 No Opera Yes Safari 不支持 No WebView Android 66 Chrome Android 66 Firefox Android 不支持 No Opera Android Yes Safari iOS 不支持 No Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

另请参阅

元数据

  • 最后修改:
  1. 接口
    1. Clipboard
    2. ClipboardEvent
    3. ClipboardItem
  2. 特性
    1. Navigator.clipboard
  3. 事件
    1. 元素 : copy
    2. 元素 : cut
    3. 元素 : paste
    4. Window : clipboardchange

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1