Reload () method:

  • This method forces the browser to refresh the current page.
  • Grammar: location. Reload ([bForceGet])
  • Parameter: bForceGet (optional, false by default) to fetch the current page from the client cache. True, then GET the latest page from the server, equivalent to the client click F5(” refresh “)

The replace () method:

  • This method replaces the item currently cached in the history (client) by specifying the URL, so when using the replace method, you cannot access the replaced URL by “going forward” or “going back.”
  • Grammar: the location. The replace (URL)


In practice, when reloading the page, we usually use: location.reload() or history.go(0). Because this is similar to how customer endpoint F5 refreshes the page, the page’s method= “post” prompts that the page is expired. That’s because of the Session security mechanism. When the location.reload() method is called, the aspx page is already in server memory, so it must be IsPostback. If there is an application where we need to reload the page, that is, we expect the page to be re-created on the server, we expect it to be Not IsPostback. In this case, location.replace() will do the job. The replaced page is regenerated on the server each time.

Return to and refresh the page:

<script language="JavaScript">
    //document.referrer Specifies the URL of the previous page
    location.replace(document.referrer);
</script>
Copy the code

Don’t use history.go(-1), or history.back(); To go back and refresh the page. These two methods do not refresh the page.

Automatic page refresh method:

  1. Automatic page refresh: Add the following code to the area< meta HTTP - equiv = "refresh" content = "20" >20 refers to refreshing the page every 20 seconds
  2. Automatic page jump: add the following code to the area< meta HTTP - equiv = "refresh" content = "20; Url = HTTP: / / http://www.baidu.con ">Where 20 fingers jump to after 20 secondsThe www.baidu.con page
  3. Page automatically refresh JS version
    <script language="JavaScript">
        function myrefresh(){
            window.location.reload();
        }
        setTimeout(' myrefresh () ',1000); // Refresh once every second
    </script>
    Copy the code
  4. If you want to refresh the window when it is closed or when it is opened, call the following statement in.
    <body onload="Opener. Location. Reload ()">Refresh when opening the window<body onUnload="Opener. Location. Reload ()">Refresh on close<script language="Javascript">
        window.opener.document.location.reload()
    </script>
    Copy the code

This article is attributed to fddcn.cn/js-shuxin.h… Please support the original