ClipboardItem.getType()
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.
getType() は ClipboardItem インターフェイスのメソッドで、要求された MIME タイプ の Blob で解決するプロミス (Promise) を返します。 MIME タイプが見つからない場合はエラーになります。
構文
js
getType(type);
引数
返値
例外
NotFoundErrorDOMException-
typeが既知の MIME タイプに一致しない。 TypeError-
引数が指定されなかった、または
typeがClipboardItemのものではない。
例
次の例では、 clipboard.read() メソッドによってクリップボード上のすべてのアイテムを返しています。そして、 ClipboardItem.types プロパティを利用して 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-gettype> |
ブラウザーの互換性
Loading…