Categories
JavaScript Answers

How to make a time delayed redirect with JavaScript?

Spread the love

Sometimes, we want to make a time delayed redirect with JavaScript.

In this article, we’ll look at how to make a time delayed redirect with JavaScript.

How to make a time delayed redirect with JavaScript?

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

For instance, we write

setTimeout(() => {
  location.href = "http://www.example.com";
}, 1500);

to call setTimeout with a callback that sets location.href to "http://www.example.com" to redirect to http://www.example.com after 1500ms.

Conclusion

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

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 *