Function Reference


Inserts HTML Text in or around an element

#include <IE.au3>
_IEDocInsertHTML ( ByRef $oObject, $sString [, $sWhere = "beforeend"] )


$oObject Object variable pointing to a document element.
$sString The string containing the HTML text to insert.
$sWhere [optional] specifies the string insertion point
    "beforebegin" = Inserts string immediately before the object.
    "afterbegin" = Inserts string after the start of the object but before all other content in the object.
    "beforeend" = (Default) Inserts string immediately before the end of the object but after all other content in the object.
    "afterend" = Inserts string immediately after the end of the object.

Return Value

Success: 1.
Failure: 0 and sets the @error flag to non-zero.
@error: 2 ($_IEStatus_COMError) - COM Error in Object reference
3 ($_IEStatus_InvalidDataType) - Invalid Data Type
4 ($_IEStatus_InvalidObjectType) - Invalid Object Type
5 ($_IEStatus_InvalidValue) - Invalid Value
@extended: Contains invalid parameter number


The innerHTML, outerHTML, innerText and outerText features of _IEPropertySet() can be used to dynamically manipulate inserted content.


_IEBodyReadHTML, _IEBodyWriteHTML, _IEDocInsertText, _IEDocReadHTML, _IEHeadInsertEventScript, _IEPropertyGet, _IEPropertySet


Example 1

; Insert HTML at the top and bottom of a document

#include <IE.au3>

Local $oIE = _IECreate("")
Local $oBody = _IETagNameGetCollection($oIE, "body", 0)
_IEDocInsertHTML($oBody, "<h2><font color=red>This HTML is inserted After Begin</font></h2>", "afterbegin")
_IEDocInsertHTML($oBody, "<h2><font color=red>This HTML is inserted Before End</font></h2>", "beforeend")

Example 2

; Open a browser with the basic example page, insert HTML
; in and around the DIV tag named "IEAu3Data" and display Body HTML

#include <IE.au3>
#include <MsgBoxConstants.au3>

Local $oIE = _IE_Example("basic")
Local $oDiv = _IEGetObjById($oIE, "IEAu3Data")

_IEDocInsertHTML($oDiv, "<b>(HTML beforebegin)</b>", "beforebegin")
_IEDocInsertHTML($oDiv, "<i>(HTML afterbegin)</i>", "afterbegin")
_IEDocInsertHTML($oDiv, "<b>(HTML beforeend)</b>", "beforeend")
_IEDocInsertHTML($oDiv, "<i>(HTML afterend)</i>", "afterend")

MsgBox($MB_SYSTEMMODAL, "Body", _IEBodyReadHTML($oIE) & @CRLF)

Example 3

; Advanced example
; Insert a clock and a referrer string at the top of every page, even when you
; browse to a new location.  Uses _IEDocInsertText, _IEDocInsertHTML and
; _IEPropertySet features "innerhtml" and "referrer"

#include <IE.au3>

Global $g_oIE = _IECreate("")

AdlibRegister("UpdateClock", 1000) ; Update clock once per second

While 1


Func UpdateClock()
        ; update as long as the browser window exists
        If Not WinExists(_IEPropertyGet($g_oIE, "hwnd")) Then Exit

        Local $sCurTime = "<font color=red><b>Current Time is: </b>" & @HOUR & ":" & @MIN & ":" & @SEC & "</font>"
        ; _IEGetObjById is expected to return a NoMatch error after navigation
        ;   (before DIV is inserted), so temporarily turn off notification
        Local $oAutoItClock = _IEGetObjById($g_oIE, "AutoItClock")
        If Not IsObj($oAutoItClock) Then ; Insert DIV element if it wasn't found
                ; Get reference to BODY, insert DIV, get reference to DIV, update time
                Local $oBody = _IETagNameGetCollection($g_oIE, "body", 0)
                _IEDocInsertHTML($oBody, "<div id='AutoItClock'></div>", "afterbegin")
                $oAutoItClock = _IEGetObjById($g_oIE, "AutoItClock")
                _IEPropertySet($oAutoItClock, "innerhtml", $sCurTime)
                ; Check referrer string, if not blank insert after clock
                Local $sReferrer = _IEPropertyGet($g_oIE, "referrer")
                If $sReferrer Then _IEDocInsertText($oAutoItClock, _
                                "  Referred by: <font color=red>" & $sReferrer & "</font>", "afterend")
                _IEPropertySet($oAutoItClock, "innerhtml", $sCurTime) ; update time
EndFunc   ;==>UpdateClock