NetworkInformation: change event

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Note: This feature is available in Web Workers.

The change event of the NetworkInformation interface fires when connection information changes, and the event is received by the NetworkInformation object.

Syntax

Use the event name in addEventListener():

js
addEventListener("change", (event) => { })

Alternatively, assign to the event handler property of the interface:

js
onchange = (event) => { }

Event type

A generic Event.

Examples

js
// Get the connection type.
const type = navigator.connection.type;

function changeHandler(e) {
  // Handle change of connection type here.
}

// Register for event changes (but note that this replaces other event listeners
// added using onchange, if any):
navigator.connection.onchange = changeHandler;

// Another way: navigator.connection.addEventListener('change', changeHandler);

Specifications

Specification
Network Information API
# dom-networkinformation-onchange

Browser compatibility