/
index.md
62 lines (41 loc) · 1.47 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
title: "USB: disconnect event"
short-title: disconnect
slug: Web/API/USB/disconnect_event
page-type: web-api-event
status:
- experimental
browser-compat: api.USB.disconnect_event
---
{{APIRef("WebUSB API")}}{{SeeCompatTable}}{{SecureContext_Header}}
The **`disconnect`** event of the {{DOMxRef("USB")}} interface is fired whenever a paired device is disconnected.
## Syntax
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
```js
addEventListener("disconnect", (event) => {});
ondisconnect = (event) => {};
```
## Event type
A {{domxref("USBConnectionEvent")}}. Inherits from {{domxref("Event")}}.
{{InheritanceDiagram("USBConnectionEvent")}}
## Event properties
_In addition to the properties listed below, properties from the parent interface, {{domxref("Event")}}, are available._
- {{domxref("USBConnectionEvent.device", "device")}} {{ReadOnlyInline}}
- : The {{domxref("USBDevice")}} the event is fired for.
## Examples
Once a USB device is disconnected, you might want to update the UI.
```js
navigator.usb.addEventListener("disconnect", (event) => {
// Remove event.device from the UI.
});
```
Alternatively, you can use the `USB.ondiscconnect` event handler property to establish a handler for the `disconnect` event:
```js
navigator.usb.ondisconnect = (event) => {
// Remove event.device from the UI.
};
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}