Knowledge about Internet Explorer

Source: Internet
Author: User
ArticleDirectory
    • Get document interface when integrating mshtml
    • Obtain the document interface when integrating browser controls
    • Obtain Document Interface from ActiveX Control
Before learning Internet Explorer programming, let's take a look at mshtml. ie implements a one-to-one object model (objectmodel) for tags in the HTML language, encapsulated by mshtml. dll. Mshtml is an object model based on COM components, and its interface is based on idispatch. For mshtml introduction, see the msdn document. For the Chinese version, refer to the following article.

About mshtml

All interfaces used to access the dynamic HTML (DHTML) object model are based on idispatch and are also the basis of the object model used for scripts. Therefore, it is important for anyone who wants to manipulate the object model to familiarize themselves with the structure and functions defined in the overview of Dynamic HTML introduction and the object model reference contained in mshtml.

Mshtml referenceThis section describes how to map objects to interfaces in the DHTML Object Model. For example, using this ing, you can see that the ihtmldocument2 interface is mapped to the Document Object. Further research on the Interface illustrates how to passGet _AndPut _Method to access the properties of the object. Methods of objects are mapped to available interfaces, and events can be captured using standard Ole automated connection points.

The example of how to make the object model interface is displayed in the colbtn, driller, and release all examples. These examples are displayed on the colbtn sample source code page, driller sample source code page, and release all sample source code page.

    • Suggestions for Using Interfaces
    • Get Document Interface
    • Document Interface
    • Related Topics
Suggestions for Using Interfaces

Generally, you can use an interface to manipulate the object model to do anything that can be done with a script in the document. Therefore, we recommend that you use the object model interfaceCodePreviously, developers should use the script design function prototype in an HTML document.

The following HTML example shows how to use the script to navigate all sets of documents and obtain the tag names of each element of the document. Equivalent use of the object model interface Microsoft (r) Visual C ++ (r) code demonstration inDriller exampleSource codePageAndWalkall sample source code page.

Example

<HTML>

<Head>

<Title> page title </title>

</Head>

<Script language = "JavaScript">

Function loaded ()

{

VaR c = Document. All. length;

VaR I;

For (I = 0; I <C; I ++)

{

Spantags. innerhtml = spantags. innerhtml + document. All. Item (I). tagname + "<br> ";

}

}

</SCRIPT>

<Body onload = "loaded ()">

<Span id = "spantags"> </span>

</Body>

</Html>

Get Document Interface

To start using the object model interface, you must obtain the ihtmldocument2 interface from the document. Once you have this interface, you can access all the elements in the document. How to obtain document interfaces depends on your applicationProgramHow to implement it. In each of the following scenarios, you must obtain the document interface in different ways.

    • When mshtml is integrated
    • When an instance of the browser control is integrated.
    • A Microsoft ActiveX (r) control contained in a webpage.
Get document interface when integrating mshtml

When an mshtml object is integrated, use cocreateinstance to create an object. Once an object is created, you can call its QueryInterface method to request iid_ihtmldocument2.Walkall sample source code pageThe example of commit all shows how to do this.

Obtain the document interface when integrating browser controls

When the browser control is integrated, perform the following steps to obtain the document interface:

    1. Call iwebbrowser2: get_document to obtainIdispatchInterface.(Note: The gethtmldocument method of the chtmlview of MFC, the document attribute of the browser control or the DOM attribute of the dhtmledit control can also be used to obtain the document interface)
    2. CallIdispatchPointer'sQueryInterfaceTo request iid_ihtmldocument2.
Obtain Document Interface from ActiveX Control

The Dynamic HTML section for accessing ActiveX documents explains how to obtain document interfaces from ActiveX (r) controls.

Document Interface

Document Interface

Once you get the documentation interface, you can use anyIhtmldocument2Interface to obtain or modify document attributes. This usually includes getting some ihtmlelementcollection interfaces from different elements in the document.

A very common set object isAllSet object.AllThe collection object uses ihtmldocument2: All(Translator's note: the original text should be changed to get_all)Method. This method returnsIhtmlelementcollectionInterface. Then you can use the ihtmlelementcollection: item method to enumerate elements.Ihtmlelementcollection: itemThe method provides you with an idispatch pointer that you can call QueryInterface to request iid_ihtmlelement. This will give you an ihtmlelement interface pointer that you can use to obtain or set information for individual elements.

most elements provide an interface to manipulate that specific element. These element-related interface names are in the ihtmlxxxxelement format. XXXX is the element name. To obtain element-related interfaces, you can call QueryInterface on the ihtmlelement interface to request the required element-related interfaces. For example, the IMG element provides an ihtmlimgelement interface to explicitly manipulate the IMG element. You can view the list of available element-related interfaces and the list of interfaces and Script objects .

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.