ExecuteScript - cWebView2Browser

Executes a script within the current top-level document of the WebView2 control

Type: Procedure

Parameters: String sScript

ParameterDescription
sScriptScript to execute


Syntax
Procedure ExecuteScript String sScript

Call: Send ExecuteScript sScript


Description

Executes a script within the current top-level document of the WebView2 control.

This method works asynchronously and will return immediately.

This method works exactly like the ExecuteScript function, except that the unique script identifier is not returned.

Sample

The example below shows how to execute a script within a page:

Object oWebView2Browser is a cWebView2Browser
    Set Size to 87 250
    Set Location to 0 0
    Set psLocationURL to "https://support.dataaccess.com"
    Set peAnchors to anAll


    Procedure OnNavigationCompleted UBigInt iNavigationId String sUrl Boolean bIsSuccess OLECOREWEBVIEW2_WEB_ERROR_STATUS eWebErrorStatus
        If (Lowercase(sUrl) contains "https://support.dataaccess.com") ;
            Send ExecuteScript @'
                function sayHello(){
                    const eWelcome = document.querySelector("ul.isuser li.welcomelink a");
                    
                    if(eWelcome){
                        alert("Hello " + eWelcome.text + "!");
                    }else{
                        alert("Hello unknown user!");
                    }
                }
                sayHello();
                '
    End_Procedure
End_Object