AddScriptToExecuteOnDocumentCreated - cWebView2Browser

Adds a script that will be executed during the loading of the future documents

Type: Function

Return Data Type: UBigInt

Parameters: String sScript

ParameterDescription
sScriptScript to execute


Return Value

Unique identifier for the load script


Syntax
Function AddScriptToExecuteOnDocumentCreated String sScript Returns UBigInt

Call: Get AddScriptToExecuteOnDocumentCreated sScript to UBigIntVariable


Description

Adds a script that will be executed during the loading of the future documents.

The script will be executed after the global object has been created but before the HTML has been parsed and scripts included from the HTML will run.

The function returns a unique identifier for the script that can be used to remove the script by calling RemoveScriptToExecuteOnDocumentCreated.

Sample

Procedure OnChange
    Boolean bChecked
    UBigInt iScriptId

    Get Checked_State to bChecked
    
    If (bChecked) Begin
        Get AddScriptToExecuteOnDocumentCreated of oWebView2BrowserCtrl 'document.addEventListener("DOMContentLoaded", function(event) { doLog("Init Script 2"); });' to iScriptId
        Set piScriptId to iScriptId
    End
    Else Begin
        Get piScriptId to iScriptId
        If (iScriptId > 0) Begin
            Send RemoveScriptToExecuteOnDocumentCreated of oWebView2BrowserCtrl iScriptId
            Set piScriptId to 0
        End
    End
End_Procedure