Callbacks when the browser goes on or offline #

Last updated March 11, 2026
domjavascript

Get callbacks when the browser goes on or offline:

const hand_online = () => {
    console.log('we are online')
}
const hand_offline = () => {
    console.log('we are offline')
}
window.addEventListener("online", hand_online)
window.addEventListener("offline", hand_offline)