JS refreshes the current page

js to refresh the current page ?

The reload method, which forces the browser to refresh the current page.

Syntax: location.reload([bForceGet])
  Parameters: bForceGet, an optional parameter, defaults to false, fetches the current page from the client cache. If true, the latest page is retrieved from the server in GET mode, which is equivalent to clicking F5 ("refresh") on the client side.

The replace method, which replaces the item currently cached in the history (client) by specifying the URL, so after using the replace method, you cannot access the replaced URL by "forward" and "backward".

Syntax: location.replace(URL)

In actual application, when refreshing the page, we usually use: location.reload() or history.go(0) to do it. Because this approach is like the client clicks F5 to refresh the page, so when the method="post" of the page, a "page expired" prompt will appear. That's because of Session's security protection mechanism. It can be imagined that when the location.reload() method is called, the aspx page already exists in the server memory at this time, so it must be IsPostback. If there is such an application: We need to reload the page, that is to say, we expect the page to be recreated on the server side, and we expect Not IsPostback. Here, location.replace() can do the job. The replaced page is regenerated on the server each 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.

 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:

**

<meta http-equiv="refresh" content="5">

Among them, content represents five fingers, which means that the page is automatically refreshed every five seconds.

Guess you like

Origin blog.csdn.net/m0_46450708/article/details/129138799