JS method to refresh the current page: 1. Reload method, this method forces the browser to refresh the current page, the syntax is "location.reload([bForceGet])"; 2. Replace method, this method specifies the URL Replace the item currently cached in the history (client), so after using the replace method, the replaced URL cannot be accessed through "forward" and "back", the syntax is "location.replace(URL)".
js Refresh the current page?
reload method, this method forces the browser to refresh the current page.
Syntax: location.reload([bForceGet]). Parameters: bForceGet, optional parameters, default is false, retrieve the current page from the client cache. If true, the latest page will be fetched from the server in GET mode, 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) Come and do it. Because this approach is like the client clicking F5 to refresh the page, so when the page's method="post" is used, a "webpage expired" prompt will appear. That's because of Session's security protection mechanism. One 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 recreated on the server side, and we expect Not IsPostback. Here, location.replace() This task can be completed. The replaced page is regenerated on the server every time.
You can write like this: location.replace(location.href).
Return and refresh the page:
location.replace(document.referrer).
document.referrer //The 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.
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
Method to automatically refresh the page:
1. Automatically refresh the page: Add the following code to the area, of which 20 Refers to refreshing the page every 20 seconds.
2. The page automatically jumps: add the following code to the area, among which 20 refers to jumping to the //www.pconline.com.cn page after 20 seconds.
The above is the detailed content of js refresh current page. For more information, please follow other related articles on the PHP Chinese website!