HIDConnectionEvent
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.
Giao diện HIDConnectionEvent của WebHID API đại diện cho các sự kiện kết nối HID, là loại sự kiện được truyền cho các trình xử lý sự kiện connect và disconnect khi trạng thái kết nối của thiết bị thay đổi.
Hàm khởi tạo
HIDConnectionEvent()Experimental-
Trả về một đối tượng
HIDConnectionEventmới. Thông thường hàm khởi tạo này không được sử dụng vì các sự kiện được tạo khi trạng thái kết nối của thiết bị thay đổi.
Thuộc tính phiên bản
Giao diện này cũng kế thừa các thuộc tính từ Event.
HIDConnectionEvent.deviceRead only Experimental-
Trả về phiên bản
HIDDeviceđại diện cho thiết bị liên kết với sự kiện kết nối.
Ví dụ
Ví dụ sau đây đăng ký các trình lắng nghe sự kiện cho các sự kiện connect và disconnect, sau đó in HIDDevice.productName ra console.
navigator.hid.addEventListener("connect", ({ device }) => {
console.log(`HID connected: ${device.productName}`);
});
navigator.hid.addEventListener("disconnect", ({ device }) => {
console.log(`HID disconnected: ${device.productName}`);
});
Thông số kỹ thuật
| Specification |
|---|
| WebHID API> # dom-hidconnectionevent> |