Frames in VBScript


An example frameset Frames can be accessed from within a frameset in a number of ways in VBScript in more or less the same fashion as in JavaScript. The only difference is syntax. Let us say for example that we have the following frameset HTML file as shown here.






















The source code for this frameset is as shown below.

<FRAMESET COLS="200,*">
	<FRAMESET COLS="200,*">
	<FRAME SRC="red.htm" NAME="leftFrame">
	<FRAMESET ROWS="50%,50%">
		<FRAME SRC="blue.htm" NAME="topFrame">
		<FRAME SRC="green.htm" NAME="bottomFrame">
	</FRAMESET>
</FRAMESET>

Accessing Frames by Number

If we wanted to change the background color frame red.htm we could do the following as an onLoad event in the frameset document.

<SCRIPT LANGUAGE="VBSCRIPT">
<!--
	Sub window_onload
		window.frames(0).document.bgColor = "#CCFF66"
	End Sub
-->
</SCRIPT>

Accessing a Frame from another Frame

We could also change the background color by accessing the frame to be changed from a subset frame of the frameset, by looking at the children of the parent frameset frame as shown below. Note that the top property accesses the topmost window, ie. the frameset window file.

<SCRIPT LANGUAGE="VBSCRIPT">
<!--
	Sub window_onload
		window.top.frames(1).document.bgcolor = "#66FFCC"
	End Sub
-->
</SCRIPT>

Accessing Frames by Name

In this case all we do is access the frames within the frameset from any frame in the frameset by the frameset NAME attribute.

<HEAD>

<SCRIPT LANGUAGE="VBSCRIPT">
<!--
	Sub btnWhite_onclick
		top.frames("bottomFrame").document.bgcolor = "WHITE"
	End Sub
	
	Sub btnRed_onclick
		top.frames("bottomFrame").document.bgcolor = "RED"
	End Sub
	
	Sub btnBlue_onclick
		top.frames("bottomFrame").document.bgcolor = "BLUE"
	End Sub
	
	Sub btnGreen_onclick
		top.frames("bottomFrame").document.bgcolor = "GREEN"
	End Sub
-->
</SCRIPT>

</HEAD>

<BODY>

<FORM>
	<INPUT TYPE="BUTTON" ID="btnWhite" VALUE="White">
	<INPUT TYPE="BUTTON" ID="btnRed" VALUE="Red">
	<INPUT TYPE="BUTTON" ID="btnGreen" VALUE="Green">
	<INPUT TYPE="BUTTON" ID="btnBlue" VALUE="Blue">
</FORM>

Targeting a Frame

Targeting a frame uses the TARGET attribute in a link tag. The first example below will bring up the web page in the frame of the frameset called bottomFrame. The second example will bring up the required web page in a separate window.

<A HREF="http://www.microsoft.com" TARGET="bottomFrame">Microsoft</A>

<A HREF="http://www.microsoft.com" TARGET="self">Microsoft</A>