
A document object represents the HTML document in a given browser window. You use the document object to retrieve information about the document, to examine and modify the HTML elements and text within the document, and to process events.
Typically, every window object has a corresponding document object that you can retrieve by calling the IUnknown::QueryInterface method with the IID_IHTMLDocument or IID_IHTMLDocument2 interface identifier. Windows that contain HTML documents always have valid document objects, but windows that contain documents in other formats might not. In general, before attempting to retrieve the document object for a window that is not the current window, make sure that the source file associated with that window is an HTML document file or a file that can be represented as an HTML document (for example, a text file).
IHTMLDocument2 Methods
HRESULT get_all(
IHTMLElementCollection **p
);
Retrieves an interface pointer to a zero-based collection of all the elements in an HTML document.
The collection includes one element object for each valid HTML tag. If a valid tag has a matching end tag, both tags are represented by the same element object. The collection always includes one element object for each of the HTML, HEAD, and BODY tags regardless of whether the tags are present in the document. If the document contains invalid or unknown tags, the collection includes one element object for each. Unlike valid end tags, unknown end tags are represented by their own element objects. The order of the element objects in the collection is the same as the order of corresponding tags in the document. Although the collection indicates the order of tags, it does not indicate which tags contain others.
You can use the length property to determine the number of element objects in the collection, and the item or tags function to retrieve individual objects or collections of objects from the collection. You can retrieve individual objects by specifying the object's index or by using its name property. Index values can be either numbers or names. Number values are zero-based, that is, 0 for the first element object, 1 for the next, and so on. A name is valid only if it is defined by a name or ID property for at least one of the elements in the collection. If the name is defined by more than one element, you can use it to retrieve a collection of all element objects that define that name.
See also get_body
HRESULT get_body(
IHTMLElement **p
);
Retrieves an interface pointer to the document's BODY object.
See also get_all
HRESULT get_activeElement(
IHTMLElement **p
);
Retrieves a pointer to the interface of the element that has the focus, which is determined by the activeElement property.
HRESULT get_images(
IHTMLElementCollection **p
);
Retrieves a pointer to the IHTMLElementCollection interface of the zero-based collection of all the images in an HTML document. The images are in the same order as they appear in the document.
HRESULT get_applets(
IHTMLElementCollection **p
);
Retrieves an interface pointer to a zero-based collection of all the APPLET objects in an HTML document. The objects are in the same order as they appear in the document.
The collection is indexed first by name, then by ID. If duplicate names are found, a collection of those named items is returned. The resulting collection can be referenced only by ordinal position.
HRESULT get_links(
IHTMLElementCollection **p
);
Retrieves an interface pointer to a zero-based collection of all the LINK and AREA objects in an HTML document. The objects are in the same order as they appear in the document.
The collection is indexed first by name, then by ID. If duplicate names are found, a collection of those named items is returned. The resulting collection can be only referenced by ordinal position.
HRESULT get_forms(
IHTMLElementCollection **p
);
Retrieves an interface pointer to a zero-based collection of all the FORM objects in an HTML document. The objects are in the same order as they appear in the document.
The collection is indexed first by name, then by ID. If duplicate names are found, a collection of those named items is returned. The resulting collection can be only referenced by ordinal position.
HRESULT get_anchors(
IHTMLElementCollection **p
);
Retrieves an interface pointer to a zero-based collection of all the A objects in an HTML document. The elements are in the same order as they appear in the document.
The collection is indexed first by name, then by ID. If duplicate names are found, a collection of those named items is returned. The resulting collection can be only referenced by ordinal position.
HRESULT put_title(
BSTR v
);
Sets the title of the document. The title identifies the contents of the document and is displayed in the header bar of the document window.
This function sets the TITLE object in the document header (defined by the HEAD object).
See also get_title
HRESULT get_title(
BSTR *p
);
Retrieves the title of the document. The title identifies the contents of the document and is displayed in the header bar of the document window.
This function retrieves the TITLE object in the document header (defined by the HEAD object).
See also put_title
HRESULT get_scripts(
IHTMLElementCollection **p
);
Retrieves an interface pointer to a zero-based collection of all the SCRIPT objects in an HTML document. The objects are in the same order as they appear in the document.
The collection is indexed first by name, then by ID. If duplicate names are found, a collection of those named items is returned. The resulting collection can only be referenced by ordinal position.
HRESULT get_selection(
IHTMLSelectionObject **p
);
Retrieves an interface pointer to an object representing the active selection. The active selection can be an insertion point, or a highlighted block of text or other elements in the document upon which the user or a script can carry out an action.
You typically use the selection object as input from the user identifying the portion of the document to act on, or as output to the user showing the results of an action.
The user, a script, or an object can create a selection. The user creates a selection by dragging the mouse over a portion of the document. A script or object creates a selection by calling the select method on a text range or similar object.
To carry out work on a selection, you can create a text range object from the selection by using the createRange method.
A document can have only one selection at a time. The selection has a type that determines whether it is empty or contains a contiguous block of consecutive text and/or elements. Although an empty selection contains nothing, it is useful for marking a position in the document.
HRESULT get_readyState(
BSTR *p
);
Retrieves the current status of an object being downloaded.
| complete | The object is completely loaded. |
| interactive | The object can be interacted with even though it is not fully loaded. |
| loading | The object is currently being loaded. |
| unitialized | The object is not created. Usually when the object is being downloaded. |
Each object can independently determine which of the three states they expose.
HRESULT get_frames(
IHTMLFramesCollection2 **p
);
Retrieves an interface pointer to a zero-based collection of all the FRAME objects in an HTML document, if the document contains the FRAMESET object. If the document contains the BODY object, this is a collection of all IFRAME objects in the document. In either case, the objects are in the same order as they appear in the document.
The collection is indexed first by name, then by ID. If duplicate names are found, a collection of those named items is returned. The resulting collection can only be referenced by ordinal position.
HRESULT get_embeds(
IHTMLElementCollection **p
);
Retrieves an interface pointer to a zero-based collection of all the EMBED objects in an HTML document. The objects are in the same order as they appear in the document.
The collection is indexed first by name, then by ID. If duplicate names are found, a collection of those named items is returned. The resulting collection can only be referenced by ordinal position.
HRESULT get_plugins(
IHTMLElementCollection **p
);
Retrieves an interface pointer to a zero-based collection of all the EMBED objects in an HTML document. The objects are in the same order as they appear in the document.
The collection is indexed first by name, then by ID. If duplicate names are found, a collection of those named items is returned. The resulting collection can only be referenced by ordinal position.
HRESULT put_alinkColor(
VARIANT v
);
Sets the color that the browser uses to indicate the active link.
See also get_alinkColor
HRESULT get_alinkColor(
VARIANT *p
);
Retrieves the color that the browser uses to indicate the active link.
See also put_alinkColor
HRESULT put_bgColor(
VARIANT v
);
Sets the background color of the page.
See also get_bgColor
HRESULT get_bgColor(
VARIANT *p
);
Retrieves the background color of the page.
See also put_bgColor
HRESULT put_fgColor(
VARIANT v
);
Sets the color of the document foreground text.
Changing this property after the document is rendered does not change the displayed color.
The default foreground color is browser specific.
See also get_fgColor
HRESULT get_fgColor(
VARIANT *p
);
Retrieves the color of the document foreground text.
Changing this property after the document is rendered does not change the displayed color.
JScript supports the entire set of valid property colors both as strings and their numerical equivalents as a string. JScript always returns the property as the numeric equivalent as a string regardless of the format to which the value was set.
The default foreground color is UA-specific.
See also put_fgColor
HRESULT put_linkColor(
VARIANT v
);
Sets the color of the document links.
See also get_linkColor
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.