草案
此页面不完整。
ClipboardItem()
constructor of the
Clipboard API
creates a new
ClipboardItem
object which represents data to be stored or retrieved via the
Clipboard API
, that is
clipboard.write()
and
clipboard.read()
分别。
注意
: Image format support varies by browser. See the browser compatibility table for the
Clipboard
接口。
var ClipboardItem = new ClipboardItem(ClipboardItemData);
注意
: To work with text see the
Clipboard.readText()
and
Clipboard.writeText()
methods of the
Clipboard
接口。
The below example requests a png image using the
抓取 API
, and in turn, the
responses' blob()
method, to create a new
ClipboardItem
and write it to the clipboard, using the
Clipboard API
.
注意 : You can only pass in one clipboard item at a time.
async function writeClipImg() {
try {
const imgURL = '/myimage.png';
const data = await fetch(imgURL);
const blob = await data.blob();
await navigator.clipboard.write([
new ClipboardItem({
[blob.type]: blob
})
]);
console.log('Fetched image copied.');
} catch(err) {
console.error(err.name, err.message);
}
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Clipboard API and events
The definition of 'ClipboardItem' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
完整支持
不支持
实验。期望将来行为有所改变。