Is there a difference between these two lines?
var url = "http://www.google.com/";
window.location = url;
window.location.replace (url);
Is there a difference between these two lines?
var url = "http://www.google.com/";
window.location = url;
window.location.replace (url);
The first one adds an item to your history in that you can (or should be able to) click "Back" and go back to the current page.
The second replaces the current history item so you can't go back to it.
See window.location
:
assign(url)
: Load the document at the provided URL.
replace(url)
:Replace the current document with the one at the provided URL. The difference from theassign()
method is that after usingreplace()
the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it.
Oh and generally speaking:
window.location.href = url;
is favoured over:
window.location = url;
worth to remember that there are browser differences in a way hash is assigned
http://artur.ejsmont.org/blog/content/window-location-hash-difference-in-ff3-and-opera