The IE Scripting Object Model VB Help

The Scripting Model is a hierarchy of objects through which you can access the properties of HfML documents displayed in the browser and the properties of the browser itself. The model’s organization is similar to the organization of the Database Access objects, which were covered in Chapter 17, Database Programming with VtSwU Basic. H you read Chapter 17,you have already seen a hierarchical organization of objects, starting with the Database object at the top.In the Scripting Model, each object has properties, which are themselves objects. As such, they have their own properties (some of them also being objects), methods, and events. The top-level object in the Scripting Model is the Wmdow object. The document is
rendered within this object. SOmebasic properties of the Wmdow object are its name (property Name) and the location of the document displayed (property URL). Before we look at these and other properties, though, let’s look at the objects of the Scripting Model at large and see what they can do for your Web pages. The most important property of the Window object is another object, the Document object. The Document object represents the H1ML document displayed in the window, which in turn has its own properties, such as background color, title, and so on, Awindow can also contain frames, which in turn can contain documents. To access the document in a frame, you first access the appropriate frame object and then the document object of the specific frame.

The Properties of the Scripting Object

The Window is the top-level object and is the container for all other objects. The Window object represents the browser’s window, in which HTML documents are displayed. Its properties include the name of the Window and the message displayed in its status bar. To access the Name property of the Window object, use a ltatement such as the following:

win_new – Window.Name

You can use the variable win_new from within your code to address the window. For example, you can request that”another document be displayed in the win new window.
To display a welcome message in the browser’s status bar, use a statement suchas the following:

Window. Status – ‘Welcome to our Fabulous Site”

You can also include VBScript functions in the definition of the status string, such as the date and time functions

Window.Status – ‘Welcome to our Fabulous Site’ & ‘It is ‘ &
date & ‘and the time is ‘ & time

The most important property of the Wmdow object is another object, the Document object. Through the Document object, you can access the properties and methods of the document displayed in the browser’s window. Two common properties of the Document object are its background color (property bgColor) and its foreground color (fgColor). To change the document’s background color to white, for example, you use the following statement:

Window.Document.bgColor =  white

Iust as some of the Window object’s properties are objects, the Document object has properties that are themselves objects. One of these objects is the Location object, with which you access the properties of the location of the document. The URL of the document in the browser’s window is given by the hRef property of the Location object. You can find out the current document’s URL or set this property to the URL of another document. The hHef property is a property of the Location object, and you access it with the following expression

Location.href

The Location object is a property of the Document object, and it must be accessed as follows:

Document. Location.href

Finally, because the Document object is a ‘property of the Window object; the complete expression for.accessing the document’s URL is the following:

Window.Document.Location.href

This expression is long, but it’s easy to understand. The first-level object is the Window object. Jhe following objects are more specific, and you can step down this hierarchy to reach the desired property. The organization of the scripting objects in a hierarchy simplifies the syntax of its methods and properties. A window can also contain frames. Frames are accessed though the Frames object, which is an array of objects. The first frame is Frames(O), the second one Frames(l), and so on. To access the document in a specific frame, you start with the Window object and specify the frame whose document you want to access. For example; if you want to access the second frame, you specify the following

Window. Frames(1)

Each frame displays a different document and therefore has its own Document property. To access the properties of the document on the second frame, use the following expression:

Window. Frames(1).Document

What would the background color of this document be? Simply tack on the bgColor property name at the end of the previous expression, and you have it:

Window.Frames(l).Document.bgColor

As you can see, the same property can be be attached to multiple objects. The window has its own Document object, and the document has a Location property. But, if the window contains frames, each frame in the window has its own location property. You may find this behavior confusing at first, but you’ll soon get the hang of it.

Posted on November 6, 2015 in Visual Basic and the Web

Share the Story

Back to Top