JavaScript: Ways to open a new page in the same window
-
02-06-2021 - |
Pergunta
location.href
location.replace
document.URL
As seen from other similar questions, can we consolidate all such possible methods?
Solução
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:
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow