In this tutorial we will learn How To Check Network Status with JavaScript. For this we can use ononline and onoffline attributes to trigger two different JavaScript functions to check the network status.
Table of Contents
HTML Code
HTML Code is given below, we have used ononline and onoffline attributes inside the body tag.
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<title>Online Offline Status Check using JavaScript</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body ononline='online()' onoffline='offline()'>
</body>
</html>
JavaScript Code
Take a look at the JavaScript code given below.
<script>
function online()
{
alert('You are online!');
}
function offline()
{
alert('You are offline!');
}
</script>
Video Tutorial
Watch video tutorial on How To Check Network Status with JavaScript.