Open In App
Related Articles

HTML | DOM Location replace() Method

Improve Article
Save Article
Like Article

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. 



<!DOCTYPE html>
<html lang="en">
    <title>DOM Location replace() Method</title>
    <h1 style="color: green">GeeksforGeeks</h1>
    <b>DOM Location replace() Method</b>
    <p>Click the button to replace
      the current document with a new one.</p>
    <button onclick="changePage()">
      Change Page
        function changePage() {
            // change the document to
            // the GeeksforGeeks homepage

Note: Run the above code on as the link used in the code is 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 1
  • Edge 12
  • Internet Explorer 5.5
  • Firefox 1
  • Opera 3
  • Safari 1
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 05 Jul, 2022
Like Article
Save Article
Similar Reads
Complete Tutorials