JS refresh the current page of several methods summary

  • 2020-03-30 01:01:46
  • OfStack

Reload method , which forces the browser to refresh the current page.

Grammar: location. Reload ([bForceGet])  

Parameter: bForceGet, optional parameter, false by default, takes the current page from the client cache. True, then GET the latest page from the server, which is equivalent to the client clicking F5(" refresh ").

The replace method , this method replaces the current cached (client) item by specifying the URL, so when using the replace method, you cannot access the already replaced URL by "forward" or "backward."
Grammar: the location. The replace (URL)      

In practice, when you're reloading a page, you usually use location.reload() or history.go(0). Because this is like the client endpoint F5 refreshing the page, the page method="post" will prompt "page expired." That's because of the Session security mechanism. As you can imagine, when the location.reload() method is called, the aspx page is already in server memory and must therefore be IsPostback. If there is an application where we need to reload the page, which means we expect the page to be re-created on the server, we expect it to be Not IsPostback. In this case, location.replace() does the job. The replaced page is regenerated each time on the server.

You can write: location.replace(location.href);

Go back and refresh the page:

The location. The replace (document. The referrer);
Document.referrer // URL of the previous page

Don't use history.go(-1), or history.back(); To go back and refresh the page. Neither method refreshes the page.

The attached:
Several ways Javascript can refresh a page:
1       History. The go (0)
2       The location. Reload ()
3       Location = location
4       The location. The assign (location)
5       Document. ExecCommand (" Refresh ")
6       Window. Navigate (location)
7       The location. The replace (location)
8       Document. The URL = location. The href

Automatic page refresh method:

1. Automatic page refresh: add the following code < Head> In the area
< Meta HTTP - equiv = "refresh" content = "20" >
Where 20 refers to refreshing the page every 20 seconds.

2. Automatic page redirect: add the following code < Head> In the area
< Meta HTTP - equiv = "refresh" content = "20; Url=//www.jb51.net ">
Where 20 refers to every 20 seconds after the jump to //www.jb51.net page

3. Page automatically refreshes js version


<script language="JavaScript">
function myrefresh()
{
       window.location.reload();
}
setTimeout('myrefresh()',1000); //Specifies
to refresh once every 1 second </script>

JS refreshes the script statement of the framework

// how to refresh the page containing the framework with    
< Script language = JavaScript>
    The parent. The location. Reload ();
< / script>    


// child window refreshes parent window
< Script language = JavaScript>
      Self. Opener. Location. Reload ();
< / script>
(or < A href = "javascript: opener. Location. Reload ()" > Refresh < / a>     )

// how to refresh the page of another frame using    
< Script language = JavaScript>
    The parent. Another FrameID. Location. Reload ();
< / script>

If you want to refresh when you want to close the window or refresh when you want to open the window, in < Body> The following statement can be called.

< The body onload = "opener. Location. Reload ()" > Refresh when opening a window
< Body onUnload = "opener. Location. Reload ()" > Refresh when closed

< Script language = "javascript" >
Window. Opener. The document. The location. Reload ()
< / script>


Related articles: