online/offline events are no longer fired on document and document.body

Published: | Categories: DOM, HTML

Description

Previously, online and offline events were fired on document.body and bubbled up to document and window, which was wrong according to the current HTML spec. Firefox 61 has fixed the non-standard behaviour so those events will be fired only on window. Note that the ononline and onoffline attributes on the <body> element are valid and therefore still available.

// Don't do this
document.body.addEventListener('online', ...);
document.body.addEventListener('offline', ...);
document.addEventListener('online', ...);
document.addEventListener('offline', ...);

// Do this
window.addEventListener('online', ...);
window.addEventListener('offline', ...);

References