How to get the browser to navigate to URL in JavaScript

jjujuma picture jjujuma · Aug 4, 2009 · Viewed 1M times · Source

What is the best (correct, modern, cross-browser, safe) way to get a web browser to navigate to a URL of your choice using JavaScript?

Answer

Paolo Bergantino picture Paolo Bergantino · Aug 4, 2009

This works in all browsers:

window.location.href = '...';

If you wanted to change the page without it reflecting in the browser back history, you can do:

window.location.replace('...');