The DOM Location replace() Method in HTML is used to replace the current document with the specified one. This method is different from the assign() method as this removes the current document from the document history, therefore it is not possible to go back to the previous document using the ‘back’ button.
location.replace( newUrl );
- newUrl: This is the URL to replace the current page with. This is a required parameter.
Note: The URL to be replaced must allow framing.
Return Value: No return value.
Note: Run the above code on ide.geeksforgeeks.org as the link used in the code is ide.geeksforgeeks.org to allow framing.
Before pressing the button:
After pressing the button:
Supported Browsers: The browser supported by DOM Location replace() Method are listed below:
- Google Chrome
- Internet Explorer
- HTML | DOM Location reload() Method
- HTML | DOM Location hostname Property
- HTML | DOM Location host Property
- HTML | DOM Location hash Property
- HTML | DOM Location pathname Property
- HTML | DOM Location protocol Property
- HTML | DOM Location href Property
- HTML | DOM Location port Property
- HTML | DOM Location origin Property
- HTML | DOM Location Search Property
- HTML | DOM KeyboardEvent location Property
- HTML DOM document location Property
- HTML DOM Window.location Property
- HTML | Location assign( ) Method
- Replace a DOM element with another DOM element in place
- Python script to open a Google Map location on clipboard
- HTTP headers | Location
- How to make workaround for window.location.href?
- HTTP headers | Content-Location
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.