HIDConnectionEvent: device property
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers("window_and_worker_except_shared")}}
The **device** read-only property of the {{domxref("HIDConnectionEvent")}} interface returns the {{domxref("HIDDevice")}} associated with this connection event.
Value
A {{domxref("HIDDevice")}}.
Examples
The following example registers event listeners for connect and disconnect events, then prints the {{domxref("HIDDevice.productName")}} to the console.
js
navigator.hid.addEventListener("connect", ({ device }) => {
console.log(`HID connected: ${device.productName}`);
});
navigator.hid.addEventListener("disconnect", ({ device }) => {
console.log(`HID disconnected: ${device.productName}`);
});Specifications
{{Specifications}}
Browser compatibility
{{Compat}}