How to detect internet connection in html page with javascript -of cource

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?

We…


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » How to detect internet connection in html page with javascript -of cource." Raghav Yadav | Sciencx - Thursday May 13, 2021, https://www.scien.cx/2021/05/13/how-to-detect-internet-connection-in-html-page-with-javascript-of-cource/
HARVARD
Raghav Yadav | Sciencx Thursday May 13, 2021 » How to detect internet connection in html page with javascript -of cource., viewed ,<https://www.scien.cx/2021/05/13/how-to-detect-internet-connection-in-html-page-with-javascript-of-cource/>
VANCOUVER
Raghav Yadav | Sciencx - » How to detect internet connection in html page with javascript -of cource. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/13/how-to-detect-internet-connection-in-html-page-with-javascript-of-cource/
CHICAGO
" » How to detect internet connection in html page with javascript -of cource." Raghav Yadav | Sciencx - Accessed . https://www.scien.cx/2021/05/13/how-to-detect-internet-connection-in-html-page-with-javascript-of-cource/
IEEE
" » How to detect internet connection in html page with javascript -of cource." Raghav Yadav | Sciencx [Online]. Available: https://www.scien.cx/2021/05/13/how-to-detect-internet-connection-in-html-page-with-javascript-of-cource/. [Accessed: ]
rf:citation
» How to detect internet connection in html page with javascript -of cource | Raghav Yadav | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.