-1

Which function in html can I use to make it ... That when I open website and become offline so it show alert that "You are offline please turn on internet connection to run website."

Prateek Chaubey
  • 166
  • 1
  • 4
  • 16
  • 6
    Possible duplicate of [Detect the Internet connection is offline?](https://stackoverflow.com/questions/189430/detect-the-internet-connection-is-offline) – Anthony L Feb 20 '18 at 04:57

2 Answers2

3

You can use window offline event

window.addEventListener('offline', function(event){
    alert("You are offline please turn on internet connection to run website");
});
Vineesh
  • 3,762
  • 20
  • 37
2

Try this.

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