This question already has answers here: How do I redirect to another webpage? (58 answers) Closed 5 years ago.
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?
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('...');
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
await t.navigateTo('http://www.google.com');
location.assign
worked in my case, thank you :)
It seems that this is the correct way window.location.assign("http://www.mozilla.org");
https://developer.mozilla.org/en-US/docs/Web/API/Window/location
https://www.w3schools.com/js/js_window_location.asp
https://web.archive.org/web/20150307183711/https://jstricks.com/javascript-redirect-page-redirection/
window.location.replace()
does NOT save the current address in history, but makes no such mention of window.location.assign()
. In my own testing with Chrome (current Mac version as of Oct 2019), window.location.assign()
DOES save the current address in the browser's history.
Success story sharing
window.location = '...'
is a synonym ofwindow.location.href = '...'
- from Window.location API.location.href
If you want to simulate an HTTP redirect, uselocation.replace
Note thatlocation.replace
does not keep the originating page in the session history.window.location.assign('...')
, which is functionally equivalent towindow.location.href = '...'
.