Window location.replace()

Example

Replace the current document:

location.replace("https://www.w3schools.com");
Try it Yourself »

Description

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

See Also:

The assign() Method

Note

The difference between assign() and replace():

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

With replace() it is not possible to use "back" to navigate back to the original document.


Syntax

location.replace(newURL)

Parameters

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

Return Value

NONE

Browser Support

location.replace() is supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.