ClipboardItem.types
Baseline
2024
Newly available
Since June 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
types は ClipboardItem インターフェイスの読み取り専用プロパティで、この ClipboardItem の内容で利用できるMIME タイプの配列 (Array) を返します。
値
例
以下の例では、 clipboard.read() メソッドによってクリップボード上のすべての項目を返しています。次に、 types プロパティで利用可能な型を確認し、 ClipboardItem.getType() メソッドを使用して Blob オブジェクトを返しています。指定されたタイプに対応するクリップボードのコンテンツが見つからない場合は、エラーが返されます。
js
async function getClipboardContents() {
try {
const clipboardItems = await navigator.clipboard.read();
for (const clipboardItem of clipboardItems) {
for (const type of clipboardItem.types) {
const blob = await clipboardItem.getType(type);
// we can now use blob here
}
}
} catch (err) {
console.error(err.name, err.message);
}
}
仕様書
| Specification |
|---|
| Clipboard API and events> # dom-clipboarditem-types> |
ブラウザーの互換性
Loading…