W3cubDocs

/Web APIs

NetworkInformation: change event

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js

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

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:
navigator.connection.onchange = changeHandler;

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

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
change_event 61 79 No No 48 No 50 38
NoOn Firefox, the event handler property corresponding to the change event is ontypechange.
45 No 3.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/change_event