Home >Web Front-end >JS Tutorial >Summary of several methods for refreshing the current page in JS_javascript skills

Summary of several methods for refreshing the current page in JS_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:07:34876browse

reload method , this method forces the browser to refresh the current page.
Syntax: location.reload([bForceGet])                                                                                    Parameters: bForceGet, optional parameter, default is false, get the current page from the client cache. true, then 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, so when using the replace method, you cannot pass "forward" and "Back" to access the URL that has been replaced.
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 pressing 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. 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.

Attachment:
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. The page automatically refreshes: add the following code to the area

where 20 means refreshing every 20 seconds One page.

2. The page automatically jumps: add the following code to the area

The 20th finger will jump to the http://www.jb51.net page after 20 seconds

< script language="JavaScript">

function myrefresh()
{

    window.location.reload();}setTimeout('myrefresh()',1000); // Specify to refresh once every second
JS refresh frame script statement

//How to refresh the page containing the frame using


//The child window refreshes the parent window

( or< ;a href="javascript:opener.location.reload()">Refresh )

//How to refresh the page of another frame using

If you want to refresh when the window is closed or refresh when the window is opened, just call the following statement in .

Refresh when the window is open
Refresh when the window is closed

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn