How to get the browser to navigate to URL in JavaScript
Advertisement
How to get the browser to navigate to URL in JavaScript
Question
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?
2018/02/06
Accepted Answer
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('...');
2009/08/04
Read more… Read less…
Try these:
window.location.href = 'http://www.google.com';
window.location.assign("http://www.w3schools.com");
window.location = 'http://www.google.com';
For more see this link: other ways to reload the page with JavaScript
2016/05/11
It seems that this is the correct way window.location.assign("http://www.mozilla.org");
2017/03/26
Licensed under CC-BY-SA with attribution
Not affiliated with Stack Overflow
Email: [email protected]