From the original SO question How to redirect to another page in jQuery?
How can I redirect from one page to another using jquery ?
From the original SO question How to redirect to another page in jQuery?
How can I redirect from one page to another using jquery ?
One doesn't redirect just using jQuery
jQuery is not required, and
window.location.replace (...)
is the best option for simulating an HTTP redirect.It's better than using
window.location.href =
, becausereplace()
it doesn't save the source page in the session history, which means the user won't be stuck in an endless back button fiasco .If you want to simulate someone clicking a link, use
location.href
.If you want to simulate an HTTP redirect, use
location.replace
.For example:
This answer uses pure jQuery to do what is asked.