reload method , which forces the browser to refresh the current page.
Syntax: location.reload([bForceGet])
Parameter: bForceGet, optional parameter, default is false, get the current page from the client cache. If true, use GET method to get the latest page from the server, which is equivalent to the client clicking F5 ("Refresh")
replace method , this method replaces the item currently cached in the history (client) by specifying the URL. Therefore, after using the replace method, you cannot access the replaced URL through "forward" and "back".
Syntax: location.replace(URL)
In actual application, when refreshing the page, we usually use: location.reload() or history.go(0). Because this approach is like the client clicking F5 to refresh the page, so when the page method="post" is used, a "webpage expired" prompt will appear. That's because of Session's security protection mechanism. You can think of: When the location.reload() method is called, the aspx page already exists in the server memory, so it must be IsPostback. If there is such an application: We need to reload the page, which means we expect the page to be re-created on the server side, and we expect Not IsPostback. Here, location.replace() can accomplish this task. The replaced page is regenerated on the server every time.
You can write: location.replace(location.href);
Go back and refresh the page:
location.replace(document.referrer);
document.referrer //URL of the previous page
Do not use history.go(-1) or history.back(); to return and refresh the page. These two methods will not refresh the page.
Attached:
Several ways to refresh the page using Javascript:
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refresh')
6 window.navigate(location)
7 location.replace(location)
8 document.URL=location.href
How to automatically refresh the page:
1. Automatic page refresh: add the following code to the <head> area
<meta http-equiv="refresh" content="20">
Among them, 20 refers to refreshing the page every 20 seconds.
2. Automatic page jump: add the following code to the <head> area
<meta http-equiv="refresh" content="20;url=//www.VeVB.COm">
Among them, 20 fingers will jump to the //www.VeVB.COm page after 20 seconds.
3. The page automatically refreshes the js version
Copy the code code as follows:
<script language="JavaScript">
function myrefresh()
{
window.location.reload();
}
setTimeout('myrefresh()',1000); //Specify a refresh time of 1 second
</script>
JS refresh frame script statement
//How to refresh the page containing this frame?
<script language=JavaScript>
parent.location.reload();
</script>
//The child window refreshes the 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
<script language=JavaScript>
parent.Another FrameID.location.reload();
</script>
If you want to refresh when the window is closed or when the window is opened, just call the following statement in <body>.
<body onload="opener.location.reload()"> Refresh when window is opened
<body onUnload="opener.location.reload()"> Refresh on close
<script language="javascript">
window.opener.document.location.reload()
</script>