MIDIPort.onstatechange

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The onstatechange event handler of the MIDIPort interface processes statechange events.

The event fires when a port changes from open to closed, or closed to open.

Syntax

MIDIPort.onstatechange = function;
MIDIPort.addEventListener('statechange', function);

Example

In the following example the current MIDIPort.state is logged each time it changes.

port.onstatechange = function() {
  console.log(port.state);
}

Specifications

Specification
Web MIDI API
# dom-midiport-onstatechange

Browser compatibility

BCD tables only load in the browser