English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Location replace() Method

JavaScript Location Object

replace()method replaces the current resource with the resource provided in the URL.

WithAssign()The difference between the two methods is that after using replace(), the current page will not be saved in the session history, which means that users will not be able to navigate to the page using the back button.

If you want to load a new document, please useassign()Method, and use options to navigate back to the original document.

Syntax:

location.replace(URL)
location.replace("https://www.oldtoolbag.com");
Test See‹/›

Browser Compatibility

All browsers fully support the replace() method:

Method
replace()YesYesYesYesYes

Parameter Value

ParameterDescription
URLA string containing the URL of the page to be viewed

Technical Details

Return Value:None

Related References

Location Reference:location.assign() method

Location Reference:location.reload() method

JavaScript Location Object