HID: sự kiện disconnect
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Note: This feature is available in Web Workers, except for Shared Web Workers.
Sự kiện disconnect của giao diện HID được phát ra khi user agent ngắt kết nối một thiết bị HID.
Cú pháp
Sử dụng tên sự kiện trong các phương thức như addEventListener(), hoặc đặt một thuộc tính trình xử lý sự kiện.
addEventListener("disconnect", (event) => { })
ondisconnect = (event) => { }
Kiểu sự kiện
Một HIDConnectionEvent. Kế thừa từ Event.
Thuộc tính sự kiện
Ngoài các thuộc tính được liệt kê bên dưới, các thuộc tính từ giao diện cha Event cũng có sẵn.
Ví dụ
Trong ví dụ sau, một trình nghe sự kiện được đăng ký để lắng nghe khi thiết bị bị ngắt kết nối. Sau đó tên của thiết bị được in ra console bằng HIDDevice.productName.
navigator.hid.addEventListener("disconnect", ({ device }) => {
console.log(`HID đã ngắt kết nối: ${device.productName}`);
});
Thông số kỹ thuật
| Specification |
|---|
| WebHID API> # dom-hid-ondisconnect> |