Coder Perfect

In JavaScript, how to cause the browser to travel to a URL [duplicate]

Problem

What is the best (proper, current, cross-browser, and safe) approach to use JavaScript to navigate a web browser to a URL of your choice?

Asked by jjujuma

Solution #1

This is compatible with all browsers:

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

If you wish to modify the page without it affecting your browser’s history, follow these steps:

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

Answered by Paolo Bergantino

Solution #2

Try these:

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

Answered by tilak

Solution #3

This appears to be the proper method window.location.assign(“http://www.mozilla.org”);

Answered by Bogdan

Post is based on https://stackoverflow.com/questions/1226714/how-to-get-the-browser-to-navigate-to-url-in-javascript