A Window Object Example

This example uses the Window object to navigate to a new URL with VBScript. The example also updates the status text to reflect the move to the new URL. Listing 3-3 shows the complete code, but note specifically that the Window object properties and methods can be called with or without explicit reference to the object. For example, the following lines of code are equivalent:

Window.Navigate "http://www.vb-bootcamp.com"
Navigate "http://www.vb-bootcamp.com" 
<HTML>
<HEAD>
<TITLE>Window object</TITLE>

<!—
This demo uses the Window object
to navigate to a new URL
—>

<SCRIPT LANGUAGE="VBScript">
<!—
    'These comment marks hide code from 
    'browsers that do not support the
    'SCRIPT tag
    'Sub cmdNavigate_OnClick
        Dim MyForm
        Set MyForm=Document.frmForm
        Window.Status="Opening " & MyForm.txtURL.Value & "…"
        Window.Navigate MyForm.txtURL.Value
    End Sub
—>
</SCRIPT>

</HEAD>
<BODY>
<CENTER>

<FORM NAME="frmForm">
<INPUT TYPE="TEXT" NAME="txtURL" 
VALUE="http://www.vb-bootcamp.com">
<INPUT TYPE="BUTTON" VALUE="Navigate" NAME="cmdNavigate">
</FORM>

</CENTER>
</BODY>
</HTML> 

Listing 3-3.

The Window object in VBScript.

Figure 3-8 shows a sample of the output.

Figure 3-8.

Sample output using the Window object.

The Window object represents the Internet Explorer itself and gives you control over the browser. The Window object is used from VBScript and is similar to the browser object we instantiated from Visual Basic earlier in this chapter. The Window object, however, offers less flexibility than the browser object accessed from Visual Basic. The Window object is limited primarily for security reasons. The VBScript code must be contained inside the browser and must allow no access to the client machine.

© 1996 by Scot Hillier. All rights reserved.