CWebView2.AddScriptToExecuteOnDocumentCreatedmethod
Add the provided JavaScript to a list of scripts that should be run after the global object has been created, but before the HTML document has been parsed and before any other script included by the HTML document is run.
Syntax
FUNCTION AddScriptToExecuteOnDocumentCreated (BYVAL javaScript AS LPCWSTR, BYVAL handler AS Afx_ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler PTR) AS HRESULT
RemoveScriptToExecuteOnDocumentCreated — one description covers them all.Parameters
| Name | Description | |
|---|---|---|
javaScript | A javascript script. | |
handler | Pointer to an ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler. |
Description
Adds/removes the provided JavaScript to a list of scripts that should be run after the global object has been created, but before the HTML document has been parsed and before any other script included by the HTML document is run.
Remarks
This method injects a script that runs on all top-level document and child frame page navigations. This method runs asynchronously, and you must wait for the completion handler to finish before the injected script is ready to run. When this method completes, the Invoke method of the handler is run with the id of the injected script. id is a string. To remove the injected script, use ^^RemoveScriptToExecuteOnDocumentCreated**.
If the method is run in AddNewWindowRequested handler it should be called before the new window is set. If called after setting the NewWindow property, the initial script may or may not apply to the initial navigation and may only apply to the subsequent navigation.
Note: If an HTML document is running in a sandbox of some kind using sandbox properties or the Content-Security-Policy HTTP header affects the script that runs. For example, if the allow-modals keyword is not set then requests to run the alert function are ignored.
Reference
- Defined in AfxNova/CWebView2.inc:1593
- Documented in WebView/CWebWiew2 Class.md
- Topic: CWebView2 Class