Advertisement
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
1
922
2/6/2018 2:54:54 PM

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
1490
8/4/2009 10:19:26 AM

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

2016/05/11


Source: https://stackoverflow.com/questions/1226714
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]