JS Refresh the current page

Source: Internet
Author: User

---restore content starts---

First, let's look at a simple example:
The following three pages were named Frame.html, top.html, bottom.html as an example to specify how to do.
Frame.html consists of two pages (top.html) under (bottom.html), the code is as follows:

For more information, refer to: http://www.jb51.net/article/14397.htm
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<TITLE> Frame </TITLE>
<frameset rows= "50%,50%" >
<frame name=top src= "top.html" >
<frame name=bottom src= "bottom.html" >

Now assume that top.html (that is, the page above) has seven buttons to implement the bottom.html (that is, the following page) refresh, you can use the following seven kinds of statements, which is good to see.
The code for the Top.html page is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<TITLE> top.html </TITLE>
<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>

Here is the bottom.html page source code, in order to prove that the page below is indeed refreshed, in the loading page pop up a dialog box.
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<TITLE> bottom.html </TITLE>
<body onload= "alert (' I was loaded! ') ' >


1.window refers to the current page, for example it refers to the top.html page.
2.parent refers to the parent page of the current page, which is the frame page that contains it. For example, in this case, it refers to framedemo.html.
3.frames is a Window object and is an array. Represents all the sub-pages within the framework.
4.item is the method. Returns the elements inside the array.
5. If the sub-page is also a frame page, inside or another sub-page, then some of the above methods may not work.
JavaScript refreshes the page in several ways:
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

Second, automatically refresh the page
1. Automatic page refresh: Add the following code to the
<meta http-equiv= "Refresh" content= ">"
20 refers to a refresh of the page every 20 seconds.
2. Page Auto-jump: Add the following code to the
<meta http-equiv= "Refresh" content= "20;url=http://www.jb51.net" >
Where 20 means jump to http://www.jb51.net page after 20 seconds
3. Page automatically refresh JS version

<script language= "JavaScript" >
function Myrefresh ()
Window.location.reload ();
SetTimeout (' Myrefresh () ', 1000); Specify 1 seconds to refresh

Third, Java in the writing servler,action, and so on, to operate back to the page (such as talking about the window, after the completion of the operation, close the current page, refresh the parent page)
1 PrintWriter out = Response.getwriter ();
2 Out.write ("<script type=\" text/javascript\ ">");
3////child window refreshes the parent window
4 Out.write ("Self.opener.location.reload ();");
5//Close window
6 Out.write ("window.opener=null;");
7 Out.write ("Window.close ();");
8 Out.write ("</script>");

Iv. script statements for JS Refresh framework
1. How to refresh the page containing the frame
<script language=javascript>
Parent.location.reload ();
2. child window Refreshes parent window

<script language=javascript>
Self.opener.location.reload ();
3. How to refresh the page of another frame (above example to illustrate)
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 ();&NBSP;
Statement 5. Window.parent.frames.item (' bottom '). Location.reload (); &NBSP;
Statement 6. Window.parent.bottom.location.reload (); Statement 7. window.parent[' Bottom '].location.reload (); 4. Call the following statement in <body> if you want to refresh the window or refresh it when you want to open it. &NBSP;
<body onload= "Opener.location.reload ()" >&NBSP;
refreshes   when window is opened;
<body onunload=" Opener.location.reload () ">&NBSP;
Refresh when off &NBSP;
<script language= "JavaScript" > &NBSP;
Window.opener.document.location.reload () &NBSP;

---restore content ends---

JS Refresh the current page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.