IHTMLElement和IHTMLElement2是IE浏览器(WebBrowser控件,trident内核)的两个同系列针对文档元素的接口。这两个接口都提供了以编程方式访问常见的所有元素对象的属性和方法的途径。 一、 下面还是先介绍IHTMLElement接口 。 IHTMLElement接口里有不少的变量和
IHTMLElement和IHTMLElement2是IE浏览器(WebBrowser控件,trident内核)的两个同系列针对文档元素的接口。这两个接口都提供了以编程方式访问常见的所有元素对象的属性和方法的途径。
一、下面还是先介绍IHTMLElement接口。
IHTMLElement接口里有不少的变量和函数,其变量大多是文档元素的属性,比如class、id、attribute、lang、tagName、InnerText、InnerHtml、OuterText、OuterHtml、child、parentElement等,还有部分是style属性,比如offsetHeight、offsetLeft、style等,另外有一部分关于该元素的动作属性,比如onclick、ondragstart、onmousedown、onmousemove等。在这些成员属性之外,还有成员方法,比如click()、getAttribute(..),另外一部分成员方法就是针对各个成员变量安排的成员函数(getXX、setXX),比如id这个属性,HRESULT get_id(BSTR *p)、HRESULT put_id(BSTR *p),对于onmousedown这个成员属性,其对应的成员函数是HRESULT get_onmousedown(VARIANT *p)、HRESULT put_onmousedown(VARIANT *p),其中VARIANT是VT_IDISPATCH类型,其细化了IDispatch接口。
all Retrieves the collection of all the objects in the HTML that are within the scope of this object.
children Retrieves the collection that contains all the immediate children of this object.
className Sets or retrieves the class of the object.
click Simulates a click by causing the onclick event to fire.
contains Checks whether the given element is contained within the object.
document Gets the document object for the document that the browser is displaying.
filters Retrieves a collection of filters for an element.
getAttribute Retrieves the value of the specified attribute.
id Sets or retrieves the string identifying the object.
innerHTML Gets or sets the HTML between the start and end tags of the object.
innerText Sets or retrieves the text between the start and end tags of the object.
insertAdjacentHTML Inserts the given HTML text into the element at the location.
insertAdjacentText Inserts the given text into the element at the specified location.
isTextEdit Retrieves whether a TextRange object can be created using the object.
lang Sets or retrieves the language to use.
language Sets or retrieves the language in which the current script is written.
offsetHeight Retrieves the height of the object relative to the layout or coordinate parent, as specified by the IHTMLElement::offsetParent property.
offsetLeft Retrieves the calculated left position of the object relative to the layout or coordinate parent, as specified by the IHTMLElement::offsetParent property.
offsetParent Retrieves a reference to the container object that defines the IHTMLElement::offsetTop and IHTMLElement::offsetLeft properties of the object.
offsetTop Retrieves the calculated top position of the object relative to the layout or coordinate parent, as specified by the IHTMLElement::offsetParent property.
offsetWidth Retrieves the width of the object relative to the layout or coordinate parent, as specified by the IHTMLElement::offsetParent property.
onafter updateSets or retrieves a pointer to the event handler function associated with the onafterupdate event.
onbeforeupdate Sets or retrieves a pointer to the event handler function associated with the onbeforeupdate event.
onclick Sets or retrieves a pointer to the event handler function associated with the onclick event.
ondataavailable Sets or retrieves a pointer to the event handler function associated with the ondataavailable event.
ondatasetchanged Sets or retrieves a pointer to the event handler function associated with the ondatasetchanged event.
ondatasetcomplete Sets or retrieves a pointer to the event handler function associated with the ondatasetcomplete event.
ondblclick Sets or retrieves a pointer to the event handler function associated with the ondblclick event.
ondragstart Sets or retrieves a pointer to the event handler function associated with the ondragstart event.
onerrorupdate Sets or retrieves a pointer to the event handler function associated with the onerrorupdate event.
onfilterchange Sets or retrieves a pointer to the event handler function associated with the event.
onhelp Sets or retrieves a pointer to the event handler function associated with the onhelp event.
onkeydown Sets or retrieves a pointer to the event handler function associated with the onkeydown event.
onkeypress Sets or retrieves a pointer to the event handler function associated with the onkeypress event.
onkeyup Sets or retrieves a pointer to the event handler function associated with the onkeyup event.
onmousedown Sets or retrieves a pointer to the event handler function associated with the onmousedown event.
onmousemove Sets or retrieves a pointer to the event handler function associated with the onmousemove event.
onmouseout Sets or retrieves a pointer to the event handler function associated with the onmouseout event.
onmouseover Sets or retrieves a pointer to the event handler function associated with the onmouseover event.
onmouseup Sets or retrieves a pointer to the event handler function associated with the onmouseup event.
onrowenter Sets or retrieves a pointer to the event handler function associated with the onrowenter event.
onrowexit Sets or retrieves a pointer to the event handler function associated with the onrowexit event.
onselectstart Sets or retrieves a pointer to the event handler function associated with the onselectstart event.
outerHTML Sets or retrieves the object and its content in HTML.
outerText Sets or retrieves the text of the object.
parentElement Retrieves the parent object in the object hierarchy.
parentTextEdit Retrieves the container object in the document hierarchy that can be used to create a TextRange containing the original object.
recordNumber Retrieves the ordinal record from the data set that generated the object.
removeAttribute Removes an attribute from an object.
scrollIntoView Causes the object to scroll into view, aligning it either at the top or bottom of the window.
setAttribute Sets the value of the specified attribute.
sourceIndex Retrieves the ordinal position of the object, in source order, as the object appears in the document's all collection.
style Retrieves an inline style sheet for the tag.
tagName Retrieves the tag name of the object.
title Sets or retrieves advisory information (a ToolTip) for the object.
toString Retrieves a string representation of the object.
二、IHTMLElement2接口的介绍
IHTMLElement2是在IHTMLElement接口基础上加了一些成员属性和方法,以满足浏览器升级的需求。其加的属性,如readyState、readyStateValue、currentStyle、与scroll(滑动条)有关的几个属性、capture、expression、behavior等属性及其设置与删除。
onpropertychange Sets or retrieves a pointer to the event handler function associated with the onpropertychange event.
onreadystatechange Sets or retrieves a pointer to the event handler function associated with the onreadystatechange event.
onresize Sets or retrieves a pointer to the event handler function associated with the onresize event.
onrowsdelete Sets or retrieves a pointer to the event handler function associated with the onrowsdelete event.
onrowsinserted Sets or retrieves a pointer to the event handler function associated with the onrowsinserted event.
onscroll Sets or retrieves a pointer to the event handler function associated with the onscroll event.
readyState Retrieves the current state of the object.
readyStateValue Gets the current state of the object.
releaseCapture Removes mouse capture from the object in the current document.
removeBehavior Detaches a behavior from the element.
removeExpression Removes the expression from the specified property.
removeFilter Not implemented.
replaceAdjacentText Replaces the text adjacent to the element.
runtimeStyle Gets the element's runtimeStyle object.
scopeName Gets the namespace defined for the element.
scrollHeight Retrieves the scrolling height of the object.
scrollLeft Sets or retrieves the distance between the left edge of the object and the leftmost portion of the content currently visible in the window.
scrollTop Sets or retrieves the distance between the top of the object and the topmost portion of the content currently visible in the window.
scrollWidth Retrieves the scrolling width of the object.
setCapture Sets the mouse capture to the object that belongs to the current document.
setExpression Sets an expression for the specified object.
tabIndex Sets or retrieves the index that defines the tab order for the object.
tagUrn Sets or gets the URN specified in the namespace declaration.
canHaveChildren Gets a value indicating whether the object can contain child objects.
下面说下IHTMLElement2接口的版本等问题。注意,IHTMLElement接口只需要IE4及其以上版本即可。
Interface Information
Stock Implementation mshtml.dll
Custom Implementation No
Inherits from IDispatch
Header and IDL files Mshtml.h, Mshtml.idl
Minimum availability Internet Explorer5
Minimum operating systems Windows 95, Windows NT 4.0, Windows CE 4.0