JavaScript implementation IFRAME Frame child page Refresh code

Source: Internet
Author: User

The framework of the refresh has always been uncertain, now think of this problem, the solution is really quite a lot, here summed up the 7 ways to refresh the frame with JS, in any of the frames page to refresh the other frames page, or more practical, these 7 methods are:

Method 1. Window.parent.frames[1].location.reload ();
Method 2. Window.parent.frames.bottom.location.reload ();
Method 3. window.parent.frames["Bottom"].location.reload ();
Method 4. Window.parent.frames.item (1). Location.reload ();
Method 5. Window.parent.frames.item (' Bottom '). Location.reload ();
Method 6. Window.parent.bottom.location.reload ();
Method 7. window.parent[' Bottom '].location.reload ();

Here is a framework to illustrate the use of these 7 methods, which includes three HTML pages:

Frame.html: The main frame, consisting of the top and bottom two child frames pages.
Top.html: On the frame.
Buttom.html: Next frame.
Assume that there is a refresh button in the top.html frame, and then click to refresh the contents of the frame bottom.html.
Main frame frame.html Code:

The code is as follows Copy Code
<HTML>
<HEAD>
<TITLE> Main Frame </TITLE>
</HEAD>
<frameset rows= "50%,50%" >
<frame name=top src= "top.html" >
<frame Name=button src= "button.html" >
</frameset>
</HTML>

On the frame top.html code, there are some refresh buttons:

The code is as follows Copy Code

<body>
<input Type=button value= "Method 1 Refresh" onclick= " Window.parent.frames[1].location.reload () "><br>
<input Type=button value=" Method 2 Refresh "onclick=" Window.parent.frames.bottom.location.reload () "><br>
<input Type=button value=" Method 3 Refresh "onclick=" window.parent.frames[' Bottom '].location.reload () ><br>
<input Type=button value= "Method 4 Refresh" onclick= " Window.parent.frames.item (1). Location.reload () "><br>
<input Type=button value=" method 5 Refresh "onclick=" Window.parent.frames.item (' Bottom '). Location.reload () "> br>
<input Type=button value=" Method 6 Refresh "onclick=" Window.parent.bottom.location.reload () "><br>
<input Type=button value=" Method 7 Refresh "onclick=" window.parent[' Bottom '].location.reload () ><br>
</body>

The next Frame bottom.html code, which is a JS window, in the frame loading, on the frame of JS is activated to demonstrate the effect of the refresh.

The code is as follows Copy Code

<HTML>
<HEAD>
</HEAD>
<body onload= "alert (' I was loaded!") ') ' >
</BODY>
</HTML>

The above 7 kinds of methods you can choose one, according to your actual situation selection, compare the entire frame to refresh the JS code.

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.