Refresh the page program code in the Javascript framework

Source: Internet
Author: User

We generally use window to refresh the framework in js. parent command, which is used to refresh the parent window in a child window. to refresh the parent window, specify the window. parent [Window name] to operate. Next I will give you an instance.


JS refresh framework script statement

The Code is as follows: Copy code

// How to refresh the page containing the framework
<Script language = JavaScript>
Parent. location. reload ();
</Script>

// Refresh the parent window in the Child Window

<Script language = JavaScript>
Self. opener. location. reload ();
</Script>
(Or <a href = "javascript: opener. location. reload ()"> refresh </a>)

// How to refresh the page of another framework
<Script language = JavaScript>
Parent. Another FrameID. location. reload ();
</Script>

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>.

The Code is as follows: Copy code

<Body onload = "opener. location. reload ()"> refresh when opening a window
<Body onUnload = "opener. location. reload ()"> refresh when disabled

<Script language = "javascript">
Zookeeper opener.doc ument. location. reload ()
</Script>

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:

The Code is as follows: Copy code

<! 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:

The Code is as follows: Copy code

<! 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.
The code for the bottom.html page is as follows:

The Code is as follows: Copy code

<! 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:

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 frame page and contains other sub-pages, some of the above methods may not work.

Let's look at another instance.

For example, the.html page has two frameworks, a1 and a2.

Function implementation: multi-layer framework nested refresh, backward, forward


Among them, B .html is included in the a2frame.
The B .html page contains two frameworks: b1 and b2.
B2frame and Webpage-specific c.html
The c.html page contains two frameworks: c1 and c2.
Now, if you want to refresh the page in the c2 framework in the a1 framework
The following code can be used:

The Code is as follows: Copy code
<A href = "javascript: window. parent. frames ['a2 ']. frames ['b2']. frames ['c2 ']. location. reload (); "> refresh <a/>

In the a1 frame, click "back" to bring the page in the c2 Frame back, as in ie.

The Code is as follows: Copy code

<A href = "javascript: window. parent. frames ['a2 ']. frames ['b2']. frames ['c2 ']. history. back (); "> back <a/>

Click "Forward" in the a1 framework to move the page in the c2 framework forward, like the forward function in ie.

The Code is as follows: Copy code

<A href = "javascript: window. parent. frames ['a2 ']. frames ['b2']. frames ['c2 ']. history. go (1); "> back <a/>

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.