IHTMLDocument2

IHTMLDocument2


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
get_all   get_body   get_activeElement  
get_images get_applets   get_links  
get_forms   get_anchors put_title  
get_title   get_scripts   get_selection  
get_readyState   get_frames get_embeds  
get_plugins   put_alinkColor   get_alinkColor
put_bgColor   get_bgColor   put_fgColor  
get_fgColor put_linkColor   get_linkColor  
put_vlinkColor   get_vlinkColor get_referrer  
get_location   get_lastModified   put_URL
get_URL   put_domain   get_domain  
put_cookie get_cookie   put_expando  
get_expando   put_charset get_charset  
put_defaultCharset   get_defaultCharset   get_mimeType  
get_fileSize   get_fileCreatedDate   get_fileModifiedDate  
get_fileUpdatedDate get_security   get_protocol  
get_nameProp   write writeln  
open   close   clear  
queryCommandSupported   queryCommandEnabled   queryCommandState  
queryCommandIndeterm   queryCommandText   queryCommandValue  
execCommand   execCommandShowHelp   createElement  
put_onhelp   get_onhelp   put_onclick  
get_onclick   put_ondblclick   get_ondblclick  
put_onkeyup   get_onkeyup   put_onkeydown  
get_onkeydown   put_onkeypress   get_onkeypress  
put_onmouseup   get_onmouseup   put_onmousedown  
get_onmousedown   put_onmousemove   get_onmousemove  
put_onmouseout   get_onmouseout   put_onmouseover  
get_onmouseover   put_onreadystatechange   get_onreadystatechange  
put_onafterupdate   get_onafterupdate   put_onrowexit  
get_onrowexit   put_onrowenter   get_onrowenter  
put_ondragstart   get_ondragstart   put_onselectstart  
get_onselectstart   elementFromPoint   get_parentWindow  
get_styleSheets   put_onbeforeupdate   get_onbeforeupdate  
put_onerrorupdate   get_onerrorupdate   toString  

IHTMLDocument2::get_all

HRESULT get_all(
    IHTMLElementCollection **p
);

Retrieves an interface pointer to a zero-based collection of all the elements in an HTML document.

p
Address of a pointer to the IHTMLElementCollection interface of the collection of elements.

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

IHTMLDocument2::get_body

HRESULT get_body(
    IHTMLElement **p
);

Retrieves an interface pointer to the document's BODY object.

p
Address of a pointer to the IHTMLElement interface of the BODY object.

See also get_all

IHTMLDocument2::get_activeElement

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.

p
Address of a pointer to the IHTMLElement interface of the element that currently has the focus.

IHTMLDocument2::get_images

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.

p
Address of a pointer to the IHTMLElementCollection interface of the images collection.

IHTMLDocument2::get_applets

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.

p
Address of a pointer to the IHTMLElementCollection interface of the applet collection.

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.

IHTMLDocument2::get_links

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.

p
Address of a pointer to the IHTMLElementCollection interface of the collection containing all the LINK and AREA elements.

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.

IHTMLDocument2::get_forms

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.

p
Address of a pointer to the IHTMLElementCollection of the collection containing all the FORM objects in an HTML 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.

IHTMLDocument2::get_anchors

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.

p
Address of a pointer to the IHTMLElementCollection interface of the collection containing all the A objects in the HTML 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.

IHTMLDocument2::put_title

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.

v
String specifying the document title.

This function sets the TITLE object in the document header (defined by the HEAD object).

See also get_title

IHTMLDocument2::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.

p
Address of a string variable that receives the title.

This function retrieves the TITLE object in the document header (defined by the HEAD object).

See also put_title

IHTMLDocument2::get_scripts

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.

p
Address of a pointer to the IHTMLElementCollection interface of the collection that contains all the SCRIPT objects.

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.

IHTMLDocument2::get_selection

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.

p
Address of a pointer to an IHTMLSelectionObject interface of the object representing the active selection.

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.

IHTMLDocument2::get_readyState

HRESULT get_readyState(
    BSTR *p
);

Retrieves the current status of an object being downloaded.

p
Address of a string variable that receives the download status of the object. Can be one of these strings:
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.

IHTMLDocument2::get_frames

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.

p
Address of a pointer to the IHTMLFramesCollection2 interface of the collection.

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.

IHTMLDocument2::get_embeds

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.

p
Address of a pointer to the IHTMLElementCollection interface of the collection.

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.

IHTMLDocument2::get_plugins

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.

p
Address of a pointer to the IHTMLElementCollection interface of the collection.

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.

IHTMLDocument2::put_alinkColor

HRESULT put_alinkColor(
    VARIANT v
);

Sets the color that the browser uses to indicate the active link.

v
VARIANT structure containing a string or value specifying the color. It can be one of the color names or values given in the Color Table reference documentation.

See also get_alinkColor

IHTMLDocument2::get_alinkColor

HRESULT get_alinkColor(
    VARIANT *p
);

Retrieves the color that the browser uses to indicate the active link.

p
Address of a VARIANT structure that receives the color. It can be one of the color names or values given in the Color Table reference documentation.

See also put_alinkColor

IHTMLDocument2::put_bgColor

HRESULT put_bgColor(
    VARIANT v
);

Sets the background color of the page.

v
VARIANT structure containing a string or value specifying the color. The color can be one of the color names or values given in the Color Table reference documentation.

See also get_bgColor

IHTMLDocument2::get_bgColor

HRESULT get_bgColor(
    VARIANT *p
);

Retrieves the background color of the page.

p
Address of a VARIANT structure that receives the color. The color can be one of the color names or values given in the Color Table reference documentation.

See also put_bgColor

IHTMLDocument2::put_fgColor

HRESULT put_fgColor(
    VARIANT v
);

Sets the color of the document foreground text.

v
VARIANT structure containing a string or value specifying the color. The color can be one of the color names or values given in the Color Table reference documentation.

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

IHTMLDocument2::get_fgColor

HRESULT get_fgColor(
    VARIANT *p
);

Retrieves the color of the document foreground text.

p
Address of a VARIANT structure that receives the color. The color can be one of the color names or values given in the Color Table reference documentation.

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

IHTMLDocument2::put_linkColor

HRESULT put_linkColor(
    VARIANT v
);

Sets the color of the document links.

v
VARIANT structure that contains a string or value specifying the color. The color can be one of the color names or values given in the Color Table reference documentation.

See also get_linkColor

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.