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.
online
は Window
インターフェイスのイベントで、ブラウザーがネットワークにアクセスできるようになり、 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 GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
online event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.