NetworkInformation: change イベント

Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。

change イベントは、接続情報が変更されたときに発行され、 NetworkInformation オブジェクトで受信されます。

構文

このイベント名を addEventListener() 等のメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。

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

onchange = (event) => { };

イベント型

一般的な Event です。

// 接続型の取得
const type = navigator.connection.type;

function changeHandler(e) {
   // ここで接続型の変更を操作する
}

// change イベントの登録
navigator.connection.onchange = changeHandler;

// 他の方法: navigator.connection.addEventListener('change', changeHandler);

仕様書

Specification
Network Information API
# dom-networkinformation-onchange

ブラウザーの互換性

BCD tables only load in the browser