Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How To Refresh a Specific Frame from Script


View products that this article applies to.

Summary

When creating Web pages that contain frames, you may wish to refresh the contents of a specific frame in response to some user interaction, such as a button click. You can perform this action using the script included in this article.

NOTE: Due to the cross-frame security model of Internet Explorer 4.0 and later, this will work only if the Web pages contained within the frames are on the same domain as the one that includes the script to refresh the frame.

↑ Back to the top


More information

Because the document object model of Internet Explorer does not contain a refresh method for frames, you can use the go method of the history object in order to refresh the contents of a specific frame.

To see how this works, copy the following HTML into the files specified and load Main.htm using Internet Explorer 4.0 or later. Then, Click Refresh in the leftmost frame. Each time one of the frames is loaded or unloaded, a message box shows you that the refresh operation was successful.

Main.htm

<HTML>
   <FRAMESET COLS="20%,40%,40%">
      <FRAME NAME="MAIN" SRC="frame1.htm">
      <FRAME SRC="frame2.htm">
      <FRAME SRC="frame3.htm">
   </FRAMESET>
</HTML>
				

Frame1.htm

<HTML>
<HEAD>
   <SCRIPT Language="VBScript">
      Sub RefreshBtn_onClick
         If Text1.Value <> "" Then
            set win = top.frames(Text1.Value - 1)
            win.History.go 0
         End If
       End Sub
   </SCRIPT>
</HEAD>

<BODY>
   Enter the number of the frame to refresh.<BR/>
   Enter 2 for frame 2, 3 for frame 3.<BR/><BR/>
   <INPUT TYPE="Text" ID="Text1"><BR/>
   <BUTTON ID="RefreshBtn">Refresh</BUTTON>
</BODY>
</HTML>
				

Frame2.htm

 <HTML>
 <SCRIPT LANGUAGE="VBScript">
    Sub Window_onLoad
       MsgBox "Frame 2 is loading"
    End Sub

    Sub Window_onUnload
       MsgBox "Frame 2 is unloading"
    End Sub
 </SCRIPT>
 <BODY>
    <H1>This is Frame 2</H1>
 </BODY>
 </HTML>
				

Frame3.htm

<HTML>
<SCRIPT LANGUAGE="VBScript">
   Sub Window_onLoad
      MsgBox "Frame 3 is loading"
   End Sub

   Sub Window_onUnload
      MsgBox "Frame 3 is unloading"
   End Sub
</SCRIPT>
<BODY>
   <H1>This is Frame 3</H1>
</BODY>
</HTML>
				

↑ Back to the top


References

For more information about the technologies discussed in this article, please refer to the documentation in the MSDN Online Web Workshop:

↑ Back to the top


Properties

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

↑ Back to the top


Keywords: KB194227, kbscript, kbhowto

↑ Back to the top

Article Info
Article ID : 194227
Revision : 3
Created on : 7/20/2012
Published on : 7/20/2012
Exists online : False
Views : 455