IWebBrowser2::Document Property

Gets the automation object of the active document, if any.

Syntax

HRESULT IWebBrowser2::get_Document(IDispatch **ppDisp);

Parameters

  • ppDisp
    Address of a pointer to a variable of type IDispatch interface that receives the automation object.

Return Value

Returns one of the following values.

S_OK The operation completed successfully.
S_FALSE Windows Internet Explorer 7. The object was not safe for scripting.
E_FAIL The operation failed.
E_INVALIDARG One or more arguments are invalid.
E_NOINTERFACE No such interface is supported.

Remarks

When the active document is an HTML page, this property provides access to the contents of the HTML  Document Object Model (DOM). Specifically, it returns an IDispatch interface pointer to the HTMLDocument component object class (coclass). The HTMLDocument coclass is functionally equivalent to the Dynamic HTML (DHTML)  document object used in HTML script. It supports all the required properties and methods to access the entire contents of the active HTML document.

C++ programs can get the Component Object Model (COM) interfaces IHTMLDocument, IHTMLDocument2, and IHTMLDocument3 by calling QueryInterface on the IDispatch received from this property.

When other document types are active, such as a Microsoft Word document, this property returns the default IDispatch dispatch interface (dispinterface) pointer for the hosted document object. For Word documents, this is functionally equivalent to the Document object in the Word object model. For more information on the Microsoft Office  DOM, refer to the Microsoft Office Developer Center.  

Warning    If the document object type is not safe for scripting, this method returns successfully but sets ppDisp to NULL. For Internet Explorer 7 and later, the return code is S_FALSE rather than S_OK. For more information, see Safe Initialization and Scripting for ActiveX Controls.

See Also

IWebBrowser2::get_Application, IWebBrowser2::get_Container, IWebBrowser2::get_Parent