What is the difference between location.replace and location.href?

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 is similar to the next web page by clicking the link.

But I really don't understand what that means.

+7
javascript dom
source share
1 answer

location.replace does not update browser history, you cannot click the back button, location.href is very much like clicking a link.

The Location.replace () method replaces the current resource with 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, which means that the user will not be able to use the "Back" button to go to it.

Source: MDN

+10
source share

All Articles