HTML中的Internet连接消失时如何显示警报



html中的哪个功能我可以用来做到...当我打开网站并脱机时,它会显示出"您处于脱机状态,请打开Internet连接到运行网站。"

您可以使用window offline事件

window.addEventListener('offline', function(event){
    alert("You are offline please turn on internet connection to run website");
});

尝试一下。

var online = navigator.onLine;
         if (online == false) 
            {
                    alert("Sorry, we currently do not have Internet access.");
                    location.reload(); 
            }

最新更新