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 the top (top.html#). The Code is as follows:
Copy codeThe 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 codeThe 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.
Copy codeThe 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:
Copy codeThe 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. Automatically refresh js version on the page

[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
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)
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 framework
Copy codeThe Code is as follows:
<Script language = JavaScript>
Parent. location. reload ();
</Script>

2. Refresh the parent window in the Child Window
Copy 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 disabled
Copy codeThe Code is as follows:
<Script language = "javascript">
Zookeeper opener.doc ument. location. reload ()
</Script>

Related Article

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.