Home >Web Front-end >JS Tutorial >A complete list of js refresh page methods_javascript skills

A complete list of js refresh page methods_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:04:58785browse

How to refresh the current page? With js you can do anything.

1, reload method, this method forces the browser to refresh the current page.
Syntax: location.reload([bForceGet])
Parameters: bForceGet, optional parameter, 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")

2. 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 use "forward" and "back" to access the item that has been cached in the history (client). The replacement URL.
Syntax: location.replace(URL)
Usually use: location.reload() or history.go(0) to do it.
This method is similar to the client point F5 to refresh the page, so when the page method="post", a "webpage expired" prompt will appear.
Because of Session’s security protection mechanism.
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: The page needs to be reloaded, which means that the page is expected to be re-created on the server side, and the expectation is Not IsPostback.
Here, location.replace() can complete this task. The replaced page is regenerated on the server every time.
Code: location.replace(location.href);

Return 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:

Copy code The code is as follows:

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

Methods to automatically refresh the page:
1. Automatically refresh the page: Add the following code to the area

Copy code The code is as follows:


20 of them means refreshing the page every 20 seconds.
2. The page will jump automatically: add the following code to the area

Copy code The code is as follows:


Among them, 20 fingers will jump to the http://www.jb51.net page after 20 seconds
3. The page will automatically refresh the js version

Copy code The code is as follows:


//The child window refreshes the parent window

( OrRefresh )
//Refresh the page of another frame with

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

Copy code The code is as follows:

Refresh when opening the window
Refresh when closing



1. Let’s take a look first A simple example:

The following takes three pages named frame.html, top.html, and bottom.html as an example to explain how to do it.
frame.html consists of two pages: top (top.html) and bottom (bottom.html). The code is as follows:
Copy code The code is as follows:



< HEAD>
frame







Now assume that top.html (i.e., the page above) has seven buttons to refresh bottom.html (i.e., the page below). You can use the following seven statements. It’s up to you which one is easier to use. The code of the
top.html page is as follows:
Copy the code The code is as follows:

< ;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


top.html </TITLE> ; <br></HEAD> <br><BODY> <br><input type=button value="Refresh 1" onclick="window.parent.frames[1].location.reload()"> ;<br> <br><input type=button value="Refresh 2" onclick="window.parent.frames.bottom.location.reload()"><br> <br><input type =button value="Refresh 3" onclick="window.parent.frames['bottom'].location.reload()"><br> <br><input type=button value="Refresh 4" onclick ="window.parent.frames.item(1).location.reload()"><br> <br><input type=button value="Refresh 5" onclick="window.parent.frames.item ('bottom').location.reload()"><br> <br><input type=button value="Refresh 6" onclick="window.parent.bottom.location.reload()"> <br> <br><input type=button value="Refresh 7" onclick="window.parent['bottom'].location.reload()"><br> <br></BODY> ; <br></HTML> <br> </div> <br>The following is the bottom.html page source code. In order to prove that the page below has indeed been refreshed, a dialog box pops up after the page is loaded. <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="25482" class="copybut" id="copybut25482" onclick="doCopy('code25482')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code25482"> <br><!DOCTYPE HTML PUBLIC "-//W3C/ /DTD HTML 4.0 Transitional//EN"> <br><HTML> <br><HEAD> <br><TITLE> bottom.html


This is the content in bottom.html.





Explain:
Copy code The code is as follows:

1.window refers to the current page, for example, in this example it refers to the top.html page.
2.parent refers to the parent page of the current page, that is, the frame page containing it. For example, for this example it refers to framedemo.html.
3.frames is a window object and an array. Represents all subpages within the frame.
4.item is a method. Returns the elements in the array.
5. If the subpage is also a frame page with other subpages inside, then some of the above methods may not work.
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

2. Automatically refresh the page
1. Automatically refresh the page: Add the following code to the area

Among them, 20 refers to refreshing the page every 20 seconds.
2. The page automatically jumps: add the following code to the area

The 20 fingers will jump to the http://www.jb51.net page after 20 seconds
3. The page automatically refreshes the js version

[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh it to execute
]

3. Java is writing Servler , Action and other programs, if you want to return to the page (such as opening the window, after the operation is completed, close the current page and refresh the parent page) The code is as follows:


1 PrintWriter out = response.getWriter();
2 out.write("");


Four. JS script statements for refreshing the frame
1. How to refresh the page containing the frame using The code is as follows:




2. The child window refreshes the parent window The code is as follows:




3. How to refresh the page of another frame (the above example illustrates ) The code is as follows:


Statement 1. window.parent.frames[1] .location.reload();
Statement 2. window.parent.frames.bottom.location.reload();
Statement 3. window.parent.frames["bottom"].location.reload();
Statement 4. window.parent.frames.item(1).location.reload();
Statement 5. window.parent.frames.item('bottom').location.reload();
Statement 6. window.parent.bottom.location.reload();
Statement 7. window.parent['bottom'].location.reload();


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

Refresh when window is open

When closed Refresh The code is as follows:


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