How to get the browser to navigate to URL in JavaScript [duplicate]

How to get the browser to navigate to URL in JavaScript [duplicate]

This question already has an answer here:

How do I redirect to another webpage?

58 answers

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?

Solutions/Answers:

Solution 1:

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('...');

Solution 2:

Try these:

  1. window.location.href = 'http://www.google.com';
  2. window.location.assign("http://www.w3schools.com");
  3. window.location = 'http://www.google.com';

For more see this link: other ways to reload the page with JavaScript

Solution 3:

It seems that this is the correct way window.location.assign("http://www.mozilla.org");