HTML onoffline Event Attribute


The event attribute onoffline occurs when the browser goes offline (when disconnected from the Internet). It can be used to alert the user that the Internet connection has been lost, or to disable some functions. These features must be enabled using the ononline attribute.


<element onoffline="script">


  • scriptThe name of the script to use when the event has been triggered.


<body ononline="onFunction()" onoffline="offFunction()">

<p>Open the File menu and click on the “Work offline” button to switch between working on onlie and offline.</p>

<p><strong>Note:</strong>Ononline and onoffline events are supported only in Firefox and Internet Explorer from versions 8 to 10.</p>

function onFunction() {
    alert ("Your browser is online.");

function offFunction() {
    alert ("Your browser is offline.");


Supported Tags


Browser Support

Explorer Edge Chrome Firefox Opera Safari
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung