Window: online イベント

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

onlineWindow インターフェイスのイベントで、ブラウザーがネットワークにアクセスできるようになり、 Navigator.onLine の値が true に切り替わると発行されます。

メモ: このイベントは、特定のウェブサイトの利用可能性を判断するために使用されるべきではありません。ネットワークの問題やファイアウォールが原因で、そのウェブサイトに到達できない可能性があります。

構文

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

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

イベント型

一般的な Event です。

イベントハンドラーの別名

Window インターフェイスに加え、 ononline イベントハンドラープロパティは以下のターゲットでも使用できます。

js
// addEventListener 版
window.addEventListener("online", (event) => {
  console.log("You are now connected to the network.");
});

// ononline 版
window.ononline = (event) => {
  console.log("You are now connected to the network.");
};

仕様書

Specification
HTML
# event-online
HTML
# handler-window-ononline

ブラウザーの互換性

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
online event

Legend

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

Full support
Full support

関連情報