javascript - Check weather internet is available or not -


this question has answer here:

i need html code. need integrate javascript in upon loading checks whether internet available or not. if active should perform specific task, else should show "no internet".

`<html>  <head>  </head>  <body onload="myclickhandler();         starttime()"> <script language="javascript">         var t;         document.onclick = myclickhandler;         function myclickhandler() {             cleartimeout(t);             t = settimeout("location.href='index.html'", 60000);            //for refreshing page in every 60 sec.         } </script> <h1> test </h1> <script type="text/javascript"> var url = "https://www.google.co.in";   var img = new image();   img.src = url;      img.onerror = function()  {     // if server down, that. alert ("no connection");         }  img.onload = function() {     // if server up, this.  //some task perform.   return true;   } </script> </body> </html>`     

this code, page keep on loading after performance need manually stop loading.

use below code. this post .

to know more navigator.online plz check below link

https://developer.mozilla.org/en-us/docs/web/api/navigatoronline/online

<!doctype html>  <html>  <head>      <script>          function checkonlinestatus(msg) {              var status = document.getelementbyid("status");              var condition = navigator.online ? "online" : "offline";                         var state = document.getelementbyid("state");              state.innerhtml = condition;                     }          function pageloaded() {              checkonlinestatus("load");              document.body.addeventlistener("offline", function () {                  checkonlinestatus("offline")              }, false);              document.body.addeventlistener("online", function () {                  checkonlinestatus("online")              }, false);          }      </script>      <style>          ...</style>  </head>  <body onload="pageloaded()">      <div id="status">          <p id="state">          </p>      </div>    </body>  </html>


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -