NetworkInformation: change イベント

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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

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

構文

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

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

onchange = (event) => {};

イベント型

一般的な Event です。

js
// 接続型の取得
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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
change event

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.