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

瀏覽器相容性

另見