草案
此页面不完整。

getType() 方法在 ClipboardItem interface returns a Promise that resolves with a Blob of the requested MIME 类型 or an error if the MIME type is not found.

句法

var blob = clipboardItem.getType(type);
					

参数

type
有效 MIME 类型 .

返回值

A Promise that resolves with a Blob 对象。

异常

DOMException
type does not match a known MIME 类型 .
TypeError
No parameter is specified or the type is not that of the ClipboardItem .

范例

In the following example, we're returning all items on the clipboard via the clipboard.read() method. Then utilizing the ClipboardItem.types property to set the getType() argument and return the corresponding blob object.

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);
  }
}
					

规范

规范 状态 注释
Clipboard API and events
The definition of 'ClipboardItem' in that specification.
工作草案 初始定义。

浏览器兼容性

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
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

图例

完整支持

完整支持

不支持

不支持

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

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

另请参阅

元数据

  • 最后修改: