This article is a mirror article of machine translation, please click here to jump to the original article.

View: 1|Reply: 0

[JavaScript] The differences between location.assign, location.href, and location.replace

[Copy link]
Posted on48 seconds ago | | |
What are the differences between window.location.assign, window.location.href, and window.location.replace?

  • window.location.href: Sets or retrieves the URL of the current document
  • window.location.assign(url): This method loads and displays the new document specified by the URL parameter, allowing users to return to the previous page via the "Back" button.
  • window.location.replace(url): This method replaces the document pointed to by the new URL without leaving any trace in the browsing history. This means that if a user tries to use the "Back" button, it will skip the replaced page and return directly to an earlier page.


window.location.href vs window.location.assign(url)

The effect is the same: both can be used to navigate to new URLs.
History: Both create a new entry in the browser's history, and users can return to the previous page via the "Back" button.

The difference is,One is the attribute, the other is the method。

window.location.assign(url) vs window.location.replace(url)

assign: Create a new history record entry,Users can retreat。
replace: Replace the current page without creating new entries in the history of the userYou cannot return using the back button。




Previous:Understanding the code_challenge and code_vertifier of PKCE in OIDC
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com