ClipboardItem.getType()
getType() は ClipboardItem インターフェイスのメソッドで、要求された MIME タイプ の Blob で解決するプロミス (Promise) を返します。 MIME タイプが見つからない場合はエラーになります。
構文
js
getType(type)
引数
type-
有効な MIME タイプです。
返値
例外
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 |
ブラウザーの互換性
BCD tables only load in the browser