I have a scenario where I wanted to check if the browser can go back to previous page via history.back(). For this purpose, I followed this answer https://stackoverflow.com/a/24056766/2948305, the code for which I am pasting below
function historyBackWFallback(fallbackUrl) {
fallbackUrl = fallbackUrl || '/';
var prevPage = window.location.href;
window.history.go(-1);
setTimeout(function(){
if (window.location.href == prevPage) {
window.location.href = fallbackUrl;
}
}, 500);
}
When window.history.go(-1) is executed, what will window.location.href resolve to ? Will it resolve current page or the previous page(history -1) .
console.log(window.location.href);
prints the current page URL. Does this mean, until the previous page is completely loaded, window.location.href will resolve to the current page.
Or until this function is fully executed(with/without the setTimeout), it will always point to current page URL.
To be specific, when exactly will window.location.href get updated?