N
2
Answers

How do I redirect a page using JavaScript?

I want to automatically redirect users from one page to another using JavaScript. What’s the correct way to do that?

Reply
Your e-mail address will not be shared with anyone.

Answers (2)

C

You can use the "window.location.href" method. Just assign a new URL to it, and it will redirect the user. Make sure you only call it when the page has loaded.

S

Another option is "window.location.replace", which doesn’t keep the current page in the history. This is useful if you don’t want users to go back to the original page.