UDF > IE >


_IEHeadInsertEventScript

Ins�re un script Java dans l'ent�te du document

#include <IE.au3>
_IEHeadInsertEventScript ( ByRef $oObject, $sHTMLFor, $sEvent, $sScript )

Param�tres

$oObject Variable objet InternetExplorer.Application, Window ou Frame
$sHTMLFor L'�l�ment HTML pour la surveillance des �v�nements (par exemple, "document", "window" ou un ID d'�l�ment)
$sEvent L'�v�nement � surveiller (par exemple "onclick" ou "oncontextmenu")
$sScript Cha�ne Javascript qui doit �tre ex�cut�e

Valeur de retour

Succ�s: Retourne 1.
�chec: Retourne 0 et d�finit @error <> 0.
@error: 2 ($_IEStatus_COMError) - Erreur COM dans la r�f�rence d'un objet
3 ($_IEStatus_InvalidDataType) - Type de donn�e invalide
@extended: Contient le nombre de param�tres invalides

Remarques

Lors de l'utilisation de ObjEvent() , AutoIt est capable d'�tre inform� des �v�nements via COM, mais il les g�re de mani�re asynchrone (plut�t que synchrone comme ils sont trait�s dans le cadre du navigateur).
Cette routine vous permet d'injecter du code qui est g�r� dans le cadre du navigateur.

Notez que les �l�ments qui n'ont pas un ID affect� peuvent encore �tre utilis�s en obtenant leurs propri�t�s "uniqueID" avec _IEPropertyGet().

En relation

_IEDocInsertHTML, _IEDocInsertText, _IEPropertyGet

Exemple

Exemple 1

; Ouvre une instance du navigateur avec la page  exemple de base, ins�re un
; �v�nement script dans l'ent�te du document qui cr�e
; une alerte JavaScript quand quelqu'un clique sur le document

#include <IE.au3>

Local $oIE = _IE_Example("basic")
_IEHeadInsertEventScript($oIE, "document", "onclick", "alert('Someone clicked the document!'); ")

Exemple 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>

Local $oIE = _IE_Example("basic")
_IEHeadInsertEventScript($oIE, "document", "oncontextmenu", "alert('No Context Menu'); return false")

Exemple 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>

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

Exemple 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>

Local $oIE = _IE_Example()
_IEHeadInsertEventScript($oIE, "document", "ondrag", "return false; ")
_IEHeadInsertEventScript($oIE, "document", "onselectstart", "return false; ")

Exemple 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>

Local $oIE = _IECreate("http://www.autoitscript.com")

Local $oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
    Local $sLinkId = _IEPropertyGet($oLink, "uniqueid")
    If @error Then Exit
    _IEHeadInsertEventScript($oIE, $sLinkId, "onclick", "return false; ")
    If @error Then Exit
    ObjEvent($oLink, "_Evt_")
Next

; idle as long as the browser window exists
While WinExists(_IEPropertyGet($oIE, "hwnd"))
    Sleep(100)
WEnd

Func _Evt_onClick()
    Local $o_Link = @COM_EventObj
    ConsoleWrite($o_Link.href & @CRLF)
EndFunc   ;==>_Evt_onClick