1

I have three webpage links, i want to switch between the pages after 30secs.

How do I do this with HTML/JS?

Use Case:

start with page abc.com
after 30secs, switch to page dfe.com
after 30secs, switch to page ghi.com 
return to page abc.com and start from above again with the timer

Thank you

dage83
  • 31
  • 4

1 Answers1

0

Your script on each page will look something like this:

<script>
    window.onloadend = () => {
        setTimeout(() => {
            location.href = "page_to_next_page";
        }, 30000); // 30000ms = 30s
    }
</script>

Here, setTimeout is used to delay execution of the function inside of it by the duration specified in milliseconds.

You'll need to add this on each page but take note this will cause the site to redirect without any interaction from the user.

Ortund
  • 8,095
  • 18
  • 71
  • 139
  • So what if I do this: ```               ``` Should't it load the first location first and reload to this other location after 5secs? – dage83 Dec 13 '21 at 13:12
  • If you do that, it'll redirect to wikipedia instantly. – Ortund Dec 13 '21 at 13:24