DEV Community

Cover image for Hey bro, you online?
Shuvo
Shuvo

Posted on

6 2

Hey bro, you online?

Sometimes the user might a have a bad internet connection which may cause your site to not function properly. So it sounds like a good idea to let your user know when the internet goes off.
And guess what? It is really easy to do using navigator.connection. Here is a basic example.

navigator.connection.onchange = function(){
    if(navigator.onLine){
        alert("Your internet connection is back");
    }else{
        alert("Your currently offline");
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
thomasbnt profile image
Thomas Bnt

Clear 👀

Collapse
 
aboss123 profile image
Ashish Bailkeri

This is pretty cool!

Collapse
 
0shuvo0 profile image
Shuvo

Glad you liked it

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay