說明
提供 chrome.clipboard
API 是為了讓使用者存取剪貼簿資料。在開放式網路替代方案推出前,這項功能是 ChromeOS 平台應用程式的暫時解決方案。開放式網路解決方案推出後,這個版本就會淘汰,時間可能在 2017 年第 4 季。
權限
clipboard
可用性
類型
AdditionalDataItem
屬性
-
資料
字串
額外資料項目的內容。如果
type
為「textPlain」,則為純文字字串;如果type
為「textHtml」,則為標記字串。資料不得超過 2 MB。 -
類型
額外資料項目的類型。
DataItemType
列舉
"textPlain"
「textHtml」
ImageType
支援的圖片類型。
列舉
「png」
「jpeg」
方法
setImageData()
chrome.clipboard.setImageData(
imageData: ArrayBuffer,
type: ImageType,
additionalItems?: AdditionalDataItem[],
callback?: function,
): Promise<void>
將圖片資料設定到剪貼簿。
參數
-
imageData
ArrayBuffer
Chrome 60 以上版本編碼後的圖片資料。
-
類型
傳遞的圖片類型。
-
additionalItems
AdditionalDataItem[] 選用
Chrome 60 以上版本用於描述圖片資料的其他資料項目。如果發生錯誤,系統會呼叫回呼,並將
chrome.runtime.lastError
設為錯誤代碼。需要 clipboard 和 clipboardWrite 權限。 -
callback
函式 選用
callback
參數如下:() => void
傳回
-
Promise<void>
Chrome 91 以上版本只有資訊清單 V3 以上版本支援 Promise,其他平台則需使用回呼。
事件
onClipboardDataChanged
chrome.clipboard.onClipboardDataChanged.addListener(
callback: function,
)
剪貼簿資料變更時觸發。如要將監聽器新增至 chrome.clipboard.onClipboardDataChanged 事件,必須具備 clipboard 和 clipboardRead 權限。這個事件觸發後,只要呼叫 document.execCommand('paste'),即可取得剪貼簿資料。
參數
-
callback
函式
callback
參數如下:() => void