What is the difference between
window.location.href="http://example.com";
window.location.replace("http://example.com");
window.location.assign("http://example.com");
I read in many forums that window.location.assign()
just replaces the current session history and hence back button of browser will not function. However, I am not able to reproduce this.
function fnSetVariable() {
//window.location.href = "http://example.com";
window.location.replace("http://example.com");
//window.location.assign("http://example.com");
}
<a onmouseover="fnSetVariable();"
href="PageCachingByParam.aspx?id=12" >
CLICK
</a>
These do the same thing:
window.location.assign(url);
window.location = url;
window.location.href = url;
They simply navigate to the new URL. The replace
method on the other hand navigates to the URL without adding a new record to the history.
So, what you have read in those many forums is not correct. The assign
method does add a new record to the history.