This article was previously published under Q194227
This article has been archived. It is offered "as is" and will no longer be updated.
When creating Web pages that contain frames, you may wish to refresh thecontents of a specific frame in response to some user interaction, such asa button click. You can perform this action using the script included inthis article.
NOTE: Due to the cross-frame security model of Internet Explorer 4.0 andlater, this will work only if the Web pages contained within the frames areon the same domain as the one that includes the script to refresh theframe.
Because the document object model of Internet Explorer does not contain arefresh method for frames, you can use the go method of the history objectin order to refresh the contents of a specific frame.
To see how this works, copy the following HTML into the files specified andload Main.htm using Internet Explorer 4.0 or later. Then, Click Refresh inthe leftmost frame. Each time one of the frames is loaded or unloaded, amessage box shows you that the refresh operation was successful.
<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>
<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>
<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>
For more information about the technologies discussed in this article,please refer to the documentation in the MSDN Online WebWorkshop: