JavaScript refreshes the page program code in the frame

Source: Internet
Author: User


JS Refresh Frame Script statement

The code is as follows Copy Code

How to refresh the page that contains the frame with
<script language=javascript>
Parent.location.reload ();
</script>

child window refreshes parent window

<script language=javascript>
Self.opener.location.reload ();
</script>
(or <a href= "javascript:opener.location.reload ()" > Refresh </a>)

How to refresh another frame's page with
<script language=javascript>
Parent. Another FrameID.location.reload ();
</script>

If you want to close the window or refresh when you want to open windows, call the following statement in <body>.

The code is as follows Copy Code

<body onload= "Opener.location.reload ()" > Refresh when opening windows
<body onunload= "Opener.location.reload ()" > Refresh when closed

<script language= "JavaScript" >
Window.opener.document.location.reload ()
</script>

The following three pages are named Frame.html, top.html, bottom.html as examples to specify how to do.

Frame.html consists of two pages (bottom.html) on top (top.html) with the following code:

The code is as follows Copy Code

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
< HTML >
< head >
< title > Frame </title >
< frameset rows = "50%,50%" >
< frame name =top src = "top.html" >
< frame name =bottom src = "bottom.html" >
</Frameset >
</HTML >

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

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 >
< 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 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.
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 >
< body onload = "alert (' I was loaded!") ') ' >
< H1 > This are the content in bottom.html. </H1 >
</Body >
</HTML >

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, which is the other child pages, then some of the above methods may not

Look at one more example

For example, the a.html page has two frames a1,a2

function realization: multi-layer frame nesting refresh, back, forward


Where the A2 frame contains the page b.html
The b.html page contains two frames b1,b2
B2 frames also contain pages c.html
The c.html page contains two frames C1,C2
Now if you want to refresh the page in the C2 frame in the A1 frame
Can be the following code

The code is as follows Copy Code
<a href= "javascript:window.parent.frames[' A2 '].frames[' B2 '"].frames["C2].location.reload" (); " > Refresh <a/>

Click "Back" in the A1 frame to let the page back in the C2 frame, like the back function 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 frame to let the page in the C2 frame go forward, like the forward function in IE

  code is as follows copy code

<a href= "Javascript:window.parent.frames[' A2 '].frames[' B2 '].frames[' C2 '"].history.go (1); " > Back <a/>

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.