Seven ways to refresh frame subpages with JavaScript

Source: Internet
Author: User
Tags array html page window
javascript| Refresh | page

Here are three pages named framedemo.html,top.html,button.html as an example to specify how to do this.

The framedemo.html consists of the top and bottom two pages, the following code:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> Framedemo </TITLE>
</HEAD>
<frameset rows= "50%,50%" >
<frame name=top src= "top.html" >
<frame Name=button src= "button.html" >
</frameset>
</HTML>

Now assume that top.html that the above page has a button to achieve the following page refresh, you can use the following seven kinds of statements, which easy to do with their own.

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 ();

Explain:

1.window refers to the current page, for example, for this 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, for this example, it refers to framedemo.html.

3.frames is a Window object and is an array. Represents all the subpages within the frame.

4.item is the method. Returns the elements inside an array.

5. If the child page is also a frames page, inside or other sub pages, then some of the above methods may not work.
top.html source code; (There are seven buttons on the page, the function is to refresh the frames page below)

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
</HEAD>
<BODY>
<input Type=button value= "Refresh 1" ><br>
<input Type=button value= "Refresh 2" ><br>
<input Type=button value= "Refresh 3" ><br>
<input Type=button value= "Refresh 4" ><br>
<input Type=button value= "Refresh 5" ><br>
<input Type=button value= "Refresh 6" ><br>
<input Type=button value= "Refresh 7" ><br>
</BODY>
</HTML>

The following is the bottom.html page source code, in order to prove that the bottom page is indeed refreshed, after loading the page pop-up a dialog box.

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
</HEAD>
<body >
</BODY>
</HTML>



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.