W3cubDocs

/Web APIs

NetworkInformation.onchange

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

The NetworkInformation.onchange event handler contains the code that is fired when connection information changes, and the change is received by the NetworkInformation object.

Syntax

netInfo.onchange = function() { ... }

Examples

// Get the connection type.
var 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
onchange
61
79
No
No
48
No
50
38
No
On Firefox, the event handler property corresponding to the change event is ontypechange.
45
No
3.0

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