ClipboardItem:presentationStyle 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

ClipboardItem 接口的只读属性 presentationStyle 返回一个字符串,指示项目应如何呈现。

例如,在某些上下文中,图像可能会以内联方式显示,而在其他上下文中,它可能被表示为附件。

可以是 "unspecified""inline""attachment" 之一。

示例

在下面的示例中,我们通过 clipboard.read() 方法返回剪贴板上的所有项目,然后记录 presentationStyle 属性。

js
async function getClipboardContents() {
  try {
    const clipboardItems = await navigator.clipboard.read();

    for (const clipboardItem of clipboardItems) {
      console.log(clipboardItem.presentationStyle);
    }
  } catch (err) {
    console.error(err.name, err.message);
  }
}

规范

规范
Clipboard API 和事件
# dom-clipboarditem-presentationstyle

浏览器兼容性

另见