ClipboardItem: thuộc tính types
Baseline
2024
Newly available
Since June 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Thuộc tính chỉ đọc types của giao diện ClipboardItem trả về một Array các MIME types hiện có trong ClipboardItem.
Giá trị
Một Array các MIME types hiện có.
Ví dụ
Trong ví dụ dưới đây, chúng ta trả về tất cả các mục trong clipboard thông qua phương thức Clipboard.read(), rồi kiểm tra thuộc tính types để lấy các kiểu hiện có trước khi dùng phương thức ClipboardItem.getType() để trả về từng mục dữ liệu dưới dạng Blob. Nếu không tìm thấy nội dung clipboard cho kiểu đã chỉ định, một lỗi sẽ được trả về.
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);
}
}
Thông số kỹ thuật
| Specification |
|---|
| Clipboard API and events> # dom-clipboarditem-types> |