HOWTO: Refresh a Specific Frame from Script
ID: Q194227
|
The information in this article applies to:
-
Microsoft Internet Explorer (Programming) versions 5.0, 4.0, 4.01, 4.01sp1, 5.0dp1
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.
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>
REFERENCES
For more information about the technologies discussed in this article,
please refer to the documentation in the MSDN Online Web
Workshop:
http://msdn.microsoft.com/workshop/
Additional query words:
Keywords : kbIE400 kbIE401 kbScript kbIE401sp1 kbIE500dp1 kbIE500
Version : WINDOWS:4.0,4.01,4.01sp1,5.0dp1
Platform : WINDOWS
Issue type : kbhowto