Js refresh PAGE method Daquan, js refresh page Daquan
How to refresh the current page? With js, you will be omnipotent.
1. reload method, which forces the browser to refresh the current page.
Syntax: location. reload ([bForceGet])
Parameter: bForceGet. An optional parameter. The default value is false. The current page is retrieved from the client cache. True, the GET method is used to obtain the latest page from the server, which is equivalent to clicking F5 ("refresh") on the client ")
2. replace method: This method replaces the items currently cached in the History (client) by specifying the URL. Therefore, after using the replace method, you cannot access the replaced URL by "Forward" or "backward.
Syntax: location. replace (URL)
Usually use location. reload () or history. go (0.
This method is similar to refreshing the page by clicking F5 on the client. Therefore, when method = "post" is displayed, the message "webpage expired" appears.
Because of the security protection mechanism of the Session.
When the location. reload () method is called, The aspx page already exists in the server memory, so it must be IsPostback.
If such an application is available, the page needs to be re-loaded. That is to say, the page is expected to be re-created on the server and Not IsPostback is expected.
Here, location. replace () can complete this task. The page to be replaced is generated on the server every time.
Code: location. replace (location. href );
Return to 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 do not refresh the page.
Appendix:
How to refresh the page with Javascript:
The Code is as follows:
1, history. go (0)
2, location. reload ()
3, location = location
4, location. assign (location)
5. document.exe cCommand ('refresh ')
6. window. navigate (location)
7, location. replace (location)
8, document. URL = location. href
How to automatically refresh the page:
1. Automatically refresh the page: Add the following code to the
The Code is as follows:
<Meta http-equiv = "refresh" content = "20">
20 indicates refreshing the page every 20 seconds.
2. automatic page Jump: Add the following code to the
The Code is as follows:
<Meta http-equiv = "refresh" content = "20; url = http://www.jb51.net">
20 means jump to the http://www.jb51.net page every 20 seconds
3. Automatically refresh the js version on the page
The Code is as follows:
<Script language = "JavaScript">
Function myrefresh ()
{
Window. location. reload ();
}
SetTimeout ('myrefresh () ', 1000); // refresh once per second
</Script>
4. JS refresh the framework script statement
The Code is as follows:
// Refresh the page containing the framework
<Script language = JavaScript>
Parent. location. reload ();
</Script>
// Refresh the parent window in the Child Window
<Script language = JavaScript>
Self. opener. location. reload ();
</Script>
(Or <a href = "javascript: opener. location. reload ()"> refresh </a>)
// Refresh the page of another framework
<Script language = JavaScript>
Parent. Another FrameID. location. reload ();
</Script>
To refresh the window when closing the window or when you want to open the window, call the following statement in <body>.
The Code is as follows:
<Body onload = "opener. location. reload ()"> refresh when opening a window
<Body onUnload = "opener. location. reload ()"> refresh when disabled
<Script language = "javascript">
Zookeeper opener.doc ument. location. reload ()
</Script>
1. Let's look at a simple example:
The following example uses the three pages separated by frame.html?top.html?bottom.html to describe how to do this.
Frame.html consists of two pages (bottom (bottom.html) under the top (top.html#). The Code is as follows:
The Code is as follows:
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TITLE> frame </TITLE>
</HEAD>
<Frameset rows = "50%, 50%">
<Frame name = top src = "top.html">
<Frame name = bottom src = "bottom.html">
</Frameset>
</HTML>
Now, let's assume that top.html (the page above) has seven buttoners to refresh bottom.html (the page below). You can use the following seven statements to see which one is easy to use.
The code for the top.html page is as follows:
The Code is as follows:
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TITLE> top.html </TITLE>
</HEAD>
<BODY>
<Input type = button value = "Refresh 1" onclick = "window. parent. frames [1]. location. reload ()"> <br>
<Input type = button value = "Refresh 2" onclick = "window. parent. frames. bottom. location. reload ()"> <br>
<Input type = button value = "Refresh 3" onclick = "window. parent. frames ['bottom ']. location. reload ()"> <br>
<Input type = button value = "Refresh 4" onclick = "window. parent. frames. item (1). location. reload ()"> <br>
<Input type = button value = "Refresh 5" onclick = "window. parent. frames. item ('bottom '). location. reload ()"> <br>
<Input type = button value = "Refresh 6" onclick = "window. parent. bottom. location. reload ()"> <br>
<Input type = button value = "Refresh 7" onclick = "window. parent ['bottom ']. location. reload ()"> <br>
</BODY>
</HTML>
The following is the source code of the bottom.html page. to verify that the page below is refreshed, a dialog box is displayed after the page is loaded.
The Code is as follows:
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TITLE> bottom.html </TITLE>
</HEAD>
<BODY onload = "alert ('I have been loaded! ') ">
<H1> This is the content in bottom.html. </BODY>
</HTML>
Explanations:
The Code is as follows:
1. windowless refers to the front page. For example, this refers to the top.html page.
2. parent refers to the parent page of the current page, that is, the framework page containing it. In this example, framedemo.html is used.
3. frames is a window object and an array. Represents all the child pages in the framework.
4. item is a method. Returns the elements in the array.
5. If the sub-page is also a framework page and contains other sub-pages, some of the above methods may not work.
Appendix:
How to refresh the page with Javascript:
1 history. go (0)
2 location. reload ()
3 location = location
4 location. assign (location)
5 document.exe cCommand ('refresh ')
6 window. navigate (location)
7 location. replace (location)
8 document. URL = location. href
Ii. Automatically refresh the page
1. Automatically refresh the page: Add the following code to the <Meta http-equiv = "refresh" content = "20">
20 indicates refreshing the page every 20 seconds.
2. automatic page Jump: Add the following code to the <Meta http-equiv = "refresh" content = "20; url = http://www.jb51.net">
20 means jump to the http://www.jb51.net page every 20 seconds
3. When java writes Servler, Action, and other programs, it needs to perform operations to return to the page (for example, after a window is opened, close the current page and refresh the parent page)
The Code is as follows:
1 PrintWriter out = response. getWriter ();
2 out. write ("<script type = \" text/javascript \ "> ");
3 //// refresh the parent window in the subwindow
4 out. write ("self. opener. location. reload ();");
5 // close the window
6 out. write ("window. opener = null ;");
7 out. write ("window. close ();");
8 out. write ("</script> ");
Iv. JS refresh framework script statement
1. How to refresh the page containing the framework
The Code is as follows:
<Script language = JavaScript>
Parent. location. reload ();
</Script>
2. Refresh the parent window in the Child Window
The Code is as follows:
<Script language = JavaScript>
Self. opener. location. reload ();
</Script>
3. How to refresh the page of another framework)
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 to refresh the window when closing the window or refresh the window when opening the window, you can call the following statement in <body>.
<Body onload = "opener. location. reload ()">
Refresh when opening window
<Body onUnload = "opener. location. reload ()">
Refresh when disabled
The Code is as follows:
<Script language = "javascript">
Zookeeper opener.doc ument. location. reload ()
</Script>