Skip to content
Related Articles

Related Articles

JavaScript | Replace() Method

View Discussion
Improve Article
Save Article
  • Last Updated : 02 Jun, 2022

The replace() method in JavaScript is used to replace the current page with another page. The Replace Method replaces the URL of the current window by the URL mention in the Replace method. 



Parameter: This method accepts single parameter URL. The URL is the reference of other page which need to replace with older page. 

Return Value: This method returns or open the new page in window. 



<!DOCTYPE html>
          <title>Redirect to Webpage</title>
            .gfg {
     <div class = "gfg">GeeksforGeeks</div>
     <h2>Replace Method</h2>
     <button onclick = "Replace()" >Replace with Gfg</button>
               //Replace function that replace the current page.
               function Replace() {

Output: Before clicking on the button: After clicking on the button:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!