How to make an alert show up when the page won't load AND it's been 7 seconds

39 views Asked by At

How to make an alert show up when the page won't load AND it's been 7 seconds.

This is the expected behavior and I would like the alert to explain to the user why this is happening. I see this code written for the time but not for the "page not loading" part.

I tried this code but I can't find information on if both the page didn't load AND it's been 7 seconds.

window.onload = setTimeout(function(){
        alert('Looks like this page hasn't loaded yet, it could be because...);
      window.location = 'EXPLANATION PAGE';
    }, 7000);
1

There are 1 answers

2
Jaromanda X On

Perhaps something along the lines of

<html>

<head>
  <script>
    let loading = setTimeout(() => {
      // do whatever you need if the page load is slow
    }, 7000);
  </script>
</head>

<body onload="clearTimeout(loading)">
</body>

</html>