Auto redirect to another web page with Javascript

In the article Auto redirect URL with meta tag HTML, we have learn about the way redirect to another page with meta tag. Today, we'll do it with Javascript.

Write a helper function:

function redirectTo(time, url) {
  setTimeout(() => {
  }, time)

In the function above, we use setTimeout function to delay the redirect action and use replace method of location to redirect URL.
The helper function have two parameters, one is delay time and another one is URL.


redirectTo(3000, ''); // The current page will be replace with after 3 seconds

© 2019 4codev

Created with love by Sil.