Display online offline connection status using JavaScript

Last Reply 6 months ago By dharmendr

Posted 6 months ago

How to displaying online offline connection status in page.

how to display a kind of popup when the network is not connected to the internet.

You are viewing reply posted by: dharmendr 6 months ago.
Posted 6 months ago

Hi arie.keren,

Check this example. The following code executes on every two second and checks if connection is there or not.

HTML

<script type="text/javascript">
    window.onload = function () {
        setInterval(function () {
            if (!navigator.onLine) {
                alert("You are not connected to Internet, ensure you're not in airplane mode. \n\nYour internet signal may be week. \n\nPlease connect to internet and try again.");
            }
        }, 2000);
    }
</script>

Demo