What is the difference between the two :
location.replace(url)
and
location.href = url
I read that the first method stimulates HTTP redirect
and the second one is similar, to following a web-page by clicking a link.
But I do not understand really,what does that mean.
What is the difference between the two :
location.replace(url)
and
location.href = url
I read that the first method stimulates HTTP redirect
and the second one is similar, to following a web-page by clicking a link.
But I do not understand really,what does that mean.
Share Improve this question edited Sep 5, 2014 at 20:56 Timo Tijhof 10.3k6 gold badges37 silver badges53 bronze badges asked Oct 2, 2013 at 6:02 Suhail GuptaSuhail Gupta 23.3k66 gold badges212 silver badges344 bronze badges 2- 3 possibly duplicate http://stackoverflow./questions/1865837/whats-the-difference-between-window-location-and-window-location-replace – jasonslyvia Commented Oct 2, 2013 at 6:04
- 2 possible duplicate of Difference between window.location.href, window.location.replace and window.location.assign – fiskeben Commented Oct 2, 2013 at 6:05
1 Answer
Reset to default 13location.replace
doesn't update the browser's history, you can't press the back button, location.href
is pretty much like clicking on a link.
The Location.replace()method replaces the current resource with the one at the provided URL. The difference from the assign() method is that after using replace() 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.
Source : MDN