Best way to redirect to another webpage in JavaScript.

Here are the best way to redirect to another page using javascript.
You can save a picture for quick reference
1. You can use window.location.href
to redirect users to another page in
a way that stores the current page in session history This will allow
users to go back to the original page.
2. You can also use window location.assign()
redirect your users to
another page. it will also simulate a link click and store the current
page in session history, it differ from window.location.replace()
in the
sense that it will tail in case or security violation.
3. If you want to redirect users to another page in a way that doesn't
store the current page in session history, you should use
window.location.replace()
. This simulates an HTTP redirect and users
will not be able to go back to the original page By clicking the back
button.
Comments