Latest web development tutorials
 

Location replace() Method

< Location Object

Example

Replace the current document:

location.replace("http://www.w3ii.com");
Try it Yourself »

Definition and Usage

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

The difference between this method and assign(), is that replace() removes the URL of the current document from the document history, meaning that it is not possible to use the "back" button to navigate back to the original document.

Tip: Use the assign() method if you want to load a new document, and the option to navigate back to the original document.


Browser Support

Method
replace() Yes Yes Yes Yes Yes

Syntax

location.replace(newURL)

Parameter Values

Parameter Type Description
newURL String Required. Specifies the URL of the page to navigate to

Return Value

No return value

< Location Object