JavaScript Answers

How to add a time delayed redirect with JavaScript?

Spread the love

To add a time delayed redirect with JavaScript, we call setTimeout.

For instance, we write

setTimeout(() => {
  window.location.href = "/blog";
}, 2000);

to call setTimeout with a callback to redirect to the /blog page after 2000 milliseconds.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *