如何在html中连接互联网时显示警报

时间:2018-02-20 04:55:21

标签: javascript html

我可以使用html中的哪个函数来制作它... 当我打开网站并离线时,它会显示警告"您离线时请打开互联网连接以运行网站。"

2 个答案:

答案 0 :(得分:2)

您可以使用window offline活动

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

答案 1 :(得分:0)

试试这个。

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