Window: offline イベント
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.
offline
は Window
インターフェイスのイベントで、ブラウザーがネットワークへのアクセスを失い、 Navigator.onLine
の値が false
に切り替わったときに発行されます。
構文
このイベント名を addEventListener()
のようなメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。
js
addEventListener("offline", (event) => {});
onoffline = (event) => {};
イベント型
一般的な Event
です。
イベントハンドラーの別名
Window
インターフェイスに加え、 onoffline
イベントハンドラープロパティは以下のターゲットでも使用できます。
例
js
// addEventListener 版
window.addEventListener("offline", (event) => {
console.log("The network connection has been lost.");
});
// onoffline 版
window.onoffline = (event) => {
console.log("The network connection has been lost.");
};
仕様書
Specification |
---|
HTML # event-offline |
HTML # handler-window-onoffline |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
offline 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.