<body>
<h1 id="text">websong</h1>
</body>
<script>
var text=document.querySelector('#text').innerText;
setInterval(function () {
if (navigator.onLine) {
//alert('online:有网络');
document.querySelector('#text').style.color='red';
document.querySelector('#text').innerText=text+'您的网络恢复了'
} else {
//alert('offline:断开网络');
document.querySelector('#text').style.color='blue';
document.querySelector('#text').innerText=text+'您断网了'
}
},1000)
</script>
亲测在各个浏览器都可以跑,当然,低版本的我没试。