JavaScript: Ways to open a new page in the same window
-
02-06-2021 - |
Question
location.href
location.replace
document.URL
As seen from other similar questions, can we consolidate all such possible methods?
Solution
var customURL = 'http://www.example.com';
window.location.href = customURL;
window.location.assign(customURL);
// Current page won't get saved in the history:
window.location.replace(customURL);
// Gecko only:
window.document.location = customURL
See also:
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow