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.
The replace() method of the Location interface 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.
Window location. The replace() method replaces the current document with a new one.
The Location href property in HTML is used to set or return the complete URL of the current page. The Location href property can also be used to set the href value point to another website or point to an email address.
window. location is an object that holds all the information about the current document location (host, href, port, protocol etc.). location. href is shorthand for window.
location.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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With