HIDConnectionEvent: device property
Khả dụng hạn chế
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.
Thuộc tính chỉ đọc device của giao diện HIDConnectionEvent trả về HIDDevice được liên kết với sự kiện kết nối này.
Giá trị
Một HIDDevice.
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.
js
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
| Thông số kỹ thuật |
|---|
| WebHID API> # dom-hidconnectionevent-device> |