代码示例:(标识:event_ononline)
<!DOCTYPE html>
<html>
<body ononline="onFunction()" onoffline="offFunction()">

<p>请打开文件菜单并单击“脱机工作”,以在联机和脱机工作之间切换。</p>

<p><b>注释:</b>ononline 和 onoffline 事件仅在 Firefox 和 Internet Explorer 版本 8 到 10 中受支持。</p>

<script>
function onFunction() {
  alert ("Your browser is working online.");
}

function offFunction() {
  alert ("Your browser is working offline.");
}
</script>

</body>
</html>
运行结果: