DEV Community

Cover image for Internet Connectivity Checker using JavaScript
Piyush | Coding Torque
Piyush | Coding Torque

Posted on

Internet Connectivity Checker using JavaScript

Hello Guys! Welcome to Welcome to Coding Torque In this blog, I'm going to explain to you how to make an internet connectivity checker using javascript. This will be a step-by-step guide including HTML and CSS. Let's get started 🚀.

Let's cover HTML Part

We use HTML to make the skeleton of a website. HTML is a markup language.

Now let's import the fonts using Google Fonts API. Below is the code for Poppins Font. Paste the below code in <head> tag.

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
Enter fullscreen mode Exit fullscreen mode

Now let's design the container in our <body> tag. In the below HTML code, we have created a container that contains a div for status (message). Next, we have the button with the onclick listener attribute, to check connectivity status by clicking on the button.

<div class="container">
    <div class="status" id="status">
        Click button to check status
    </div>
    <button onclick="checkConnectivityStatus()">Check Status</button>
</div>
Enter fullscreen mode Exit fullscreen mode

Here is the final HTML code

<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Google Fonts  -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">

    <title>Internet Connectivity Detector using JavaScript - @code.scientist x @codingtorque</title>
</head>

<body>
    <div class="container">
        <div class="status" id="status">
            Click button to check status
        </div>
        <button onclick="checkConnectivityStatus()">Check Status</button>
    </div>

</body>

</html>
Enter fullscreen mode Exit fullscreen mode

Output Till Now

Image description

continue reading

Top comments (1)

Collapse
 
jcubic profile image
Jakub T. Jankiewicz • Edited

You don't need to click on the button. There is an even that change state when you get offline and get back online.