This content originally appeared on DEV Community and was authored by Raghav Yadav
Detecting the user's state of being online or offline is very important for a progressive web app to develop it tells the if a person is online or offline without importing any file and in a less time period.
The question is how do we detect that?
Well like always you can include a cdn:
<script src="https://netopa.github.io/hash.js/hashtag_1.0.1.js"></script>
And return true or false with a simple code:
hash().isOnline(); //returns true or false
And there are many other things you can do with this library to which I have mentioned in my previous article
OR going the other way:
Well navigator can help in this stage:
if(navigator.online){
//online
}else{
//offline
}
That's all and make sure to hit the like if you liked the article and gift yourself a coffee from me ;)
This content originally appeared on DEV Community and was authored by Raghav Yadav
Raghav Yadav | Sciencx (2021-05-13T03:43:07+00:00) How to detect internet connection in html page with javascript -of cource. Retrieved from https://www.scien.cx/2021/05/13/how-to-detect-internet-connection-in-html-page-with-javascript-of-cource/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.