JS page refresh Methods

Source: Internet
Author: User

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 top.html,CodeAs follows:

Copy code 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: Copy code 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>

below is the bottom.html page Source Code . to verify that the page below is refreshed, a dialog box is displayed on the page after loading. copy Code the code is as follows:


bottom.html </ title>


this is the content in bottom.html.



explanation: copy Code the code is as follows: 1. Windows indicates the front page. For example, this example indicates 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 child page is also a frame page and contains other child pages, some of the above methods may not work.
Appendix:
methods for refreshing the page using 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

2. Automatically refresh the page
1. automatic page Refresh: add the following code to the area

20 indicates refreshing the page every 20 seconds.
2. automatic page Jump: Add the following code to the area

20 means jump to the http://www.jb51.net page every 20 seconds
3. page Auto-Refresh JS version
[Ctrl + A select all Note: To introduce external JS, refresh it before execution]

Iii. Write servler and action in JavaProgramTo return to the page (for example, after the window is displayed, close the current page and refresh the parent page)Copy codeThe 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 frameworkCopy codeThe Code is as follows: <script language = JavaScript>
Parent. Location. Reload ();
</SCRIPT>

2. Refresh the parent window in the Child WindowCopy codeThe Code is as follows: <script language = JavaScript>
Self. opener. Location. Reload ();
</SCRIPT>

3. How to refresh the page of another framework)Copy codeThe 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 disabledCopy codeThe Code is as follows: <script language = "JavaScript">
Zookeeper opener.doc ument. Location. Reload ()
</SCRIPT>

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.