0

I want to make a weak network detector. I have already made an offline and an online detector. Like this: And of course with some JavaScript.

<body onoffline="offlineDetect()" ononline="onlineDetect()">

So my question is that is there any way to check is the connecton is above than for example 400ms, and if the ping reaches the 400ms a warning message appear?

scrummy
  • 795
  • 1
  • 6
  • 20
  • 1
    you can maybe ping a server like you do with onlineDetect, but timing the ms to get the ping response? Maybe look at the second answer here https://stackoverflow.com/questions/4282151/is-it-possible-to-ping-a-server-from-javascript – gbos Jan 11 '21 at 12:17

1 Answers1

1
 <script>
window.addEventListener('load', function() {
  var status = document.getElementById("status");
  var log = document.getElementById("log");

  function updateOnlineStatus(event) {
    var condition = navigator.onLine ? "online" : "offline";

    status.className = condition;
    status.innerHTML = condition.toUpperCase();

    log.insertAdjacentHTML("beforeend", "Event: " + event.type + "; Status: " + condition);
  }

  window.addEventListener('online',  updateOnlineStatus);
  window.addEventListener('offline', updateOnlineStatus);
});
</script>
<div id="status"></div>
<div id="log"></div>
<p>This is a test</p>
MH Fuad
  • 746
  • 6
  • 16