↑  ←  Описание функции


_IEHeadInsertEventScript

Inserts a Javascript into the Head of the document.

#include <IE.au3>
_IEHeadInsertEventScript(ByRef $o_object, $s_htmlFor, $s_event, $s_script)

Параметры

$o_object Переменная объекта InternetExplorer.Application, объекта Окна или Фрейма (области)
$s_htmlFor The HTML element for event monitoring (e.g. "document", "window" or an element ID)
$s_event The event to monitor (e.g. "onclick" or "oncontextmenu")
$s_script Javascript string to be executed

Возвращаемое значение

Успех:Возвращает 1
Ошибка:Возвращает 0 и устанавливает @error
@error:0 ($_IEStatus_Success) = Нет ошибок
3 ($_IEStatus_InvalidDataType) = Неверный тип данных
@extended:Содержит номер неверного параметра

Примечания

Using ObjEvent, AutoIt is able to be notified of events via COM, but it manages them asynchronously (rather than synchronously as they are handled in the browser context). This routine allows you to inject code that is managed inside the browser context.

Note that elements that do not have an ID assigned can still be used by obtaining their "uniqueID" property with _IEPropertyGet

См. также

_IEDocInsertHTML, _IEPropertyGet, _IEDocInsertText

Пример

; *******************************************************
; Пример 1 - Open a browser with the basic example page, insert an
;               event script into the head of the document that creates
;               a JavaScript alert when someone clicks on the document
; *******************************************************

#include <IE.au3>
$oIE = _IE_Example ("basic")
_IEHeadInsertEventScript ($oIE, "document", "onclick", "alert('Someone clicked the document!');")

; *******************************************************
; Пример 2 - Open a browser with the basic example page, insert an
;               event script into the head of the document that creates
;               a JavaScript alert when someone tries to right-click on the
;               document and then the event script returns "false" to prevent
;               the right-click context menu from appearing
; *******************************************************

#include <IE.au3>
$oIE = _IE_Example ("basic")
_IEHeadInsertEventScript ($oIE, "document", "oncontextmenu", "alert('No Context Menu');return false")

; *******************************************************
; Пример 3 - Open a browser with the basic example page, insert an
;               event script into the head of the document that creates a
;               JavaScript alert when we are about to navigate away from the
;               page and presents the option to cancel the operation.
; *******************************************************

#include <IE.au3>
$oIE = _IE_Example ("basic")
_IEHeadInsertEventScript ($oIE, "window", "onbeforeunload", _
    "alert('Example warning follows...');return 'Pending changes may be lost';")
_IENavigate($oIE, "www.autoitscript.com")

; *******************************************************
; Пример 4 - Open a browser with the basic example page, insert an
;               event script into the head of the document that prevents
;               selection of text in the document
; *******************************************************

#include <IE.au3>
$oIE = _IE_Example()
_IEHeadInsertEventScript ($oIE, "document", "ondrag", "return false;")
_IEHeadInsertEventScript ($oIE, "document", "onselectstart", "return false;")

; *******************************************************
; Пример 5 - Open a browser with the AutoIt homepage, insert an
;               event script into the head of the document that prevents
;               navigation when any link is clicked and log the URL of the
;               clicked link to the console
; *******************************************************

#include <IE.au3>

$oIE = _IECreate("http://www.autoitscript.com")
$oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
    $sLinkId = _IEPropertyGet($oLink, "uniqueid")
    _IEHeadInsertEventScript($oIE, $sLinkId, "onclick", "return false;")
    ObjEvent($oLink, "_Evt_")
Next

While 1
    Sleep(100)
WEnd

Func _Evt_onClick()
    Local $o_link = @COM_EventObj
    ConsoleWrite($o_link.href & @CRLF)
EndFunc