USBConnectionEvent
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
Giao diện USBConnectionEvent của WebUSB API là loại sự kiện được truyền vào các sự kiện USB connect và disconnect khi user agent phát hiện một thiết bị USB mới được kết nối hoặc ngắt kết nối.
Hàm khởi tạo
USBConnectionEvent()Experimental-
Trả về một đối tượng
USBConnectionEvent.
Thuộc tính phiên bản
USBConnectionEvent.deviceRead only Experimental-
Trả về một đối tượng
USBDeviceđại diện cho thiết bị hiện tại.
Ví dụ
Trong ví dụ sau, việc lắng nghe các sự kiện connect và disconnect được sử dụng để thêm và xóa các thiết bị khỏi giao diện người dùng của ứng dụng.
navigator.usb.addEventListener("connect", (event) => {
// Add event.device to the UI.
});
navigator.usb.addEventListener("disconnect", (event) => {
// Remove event.device from the UI.
});
Thông số kỹ thuật
| Specification |
|---|
| WebUSB API> # usbconnectionevent> |