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

Specification
Network Information API
# dom-networkinformation-onchange

Browser compatibility

BCD tables only load in the browser