window.location object should be used. There are two commonly used approaches, the
window.location.replace() method and the
window.location.href variable. Understanding the differences between the two is important.
For a standard redirect,
replace() is usually the best approach.
It’s better than using
window.location.href = … because
replace() skips the browser’s history. This ensures that users do not get stuck in a never-ending back-button redirect loop.
User Clicking a Link
window.location.href = "http://www.google.com";
This method mimics the events that occur when a user clicks a link.
About the Author
Kevin Leary is a web developer in Boston, MA specializing in enterprise website design and development, online marketing, and conversion optimization.