NetworkInformation: change event
Network Information API
Network Information API
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():
addEventListener("change", (event) => { })
Alternatively, assign to the event handler property of the interface:
onchange = (event) => { }
Event type
A generic Event.
Examples
// 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);