Window location.replace() method

Definition and usage

replace() The method replaces the current document with a new document.

See also:

assign() method

Difference between assign() and replace():

replace() Remove the current URL from the document history.

Use replace() Cannot navigate back to the original document using the 'Back' button.

Example

Replace the current document:

location.replace("https://www.codew3c.com");

Try it yourself

Syntax

location.replace(newURL)

Parameter

Parameter Description
newURL Required. The URL of the page to navigate to.

Return value

None.

Browser support

All browsers support location.replace():

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support