Executes JavaScript code in the context of the loaded HTML document.
Takes htmlViewID (Int) and script (String).
Returns value (script result discarded).
BGI GUI
Parameters & Returns
Parameters
htmlViewIDInt
scriptString
Returns
Void
Quick Summary
Executes JavaScript code in the context of the loaded HTML document.
Takes htmlViewID (Int) and script (String).
Returns value (script result discarded).
Technical Exegesis...
Executes JavaScript code in the context of the loaded HTML document. Searches webBrowserMap for htmlViewID. If found, gets IWebBrowser2* interface. Gets IDispatch via get_Document(), queries for IHTMLDocument2. Calls get_parentWindow() to obtain IHTMLWindow2 interface. Converts UTF-8 script string to BSTR using MultiByteToWideChar. Calls pWindow->execScript(bstrScript, L"JavaScript", &vResult) to execute JavaScript. SysFreeString releases BSTR. Releases COM interfaces.
Executes JavaScript code in the context of the loaded HTML document. Searches webBrowserMap for htmlViewID. If found, gets IWebBrowser2* interface. Gets IDispatch via get_Document(), queries for IHTMLDocument2. Calls get_parentWindow() to obtain IHTMLWindow2 interface. Converts UTF-8 script string to BSTR using MultiByteToWideChar. Calls pWindow->execScript(bstrScript, L"JavaScript", &vResult) to execute JavaScript. SysFreeString releases BSTR. Releases COM interfaces. No return value (script result discarded).
This function injects and executes JavaScript code in the WebBrowser's JavaScript runtime context. execScript() runs code synchronously - function blocks until script completes. Script has full access to document DOM, window object, and global JavaScript context. Can manipulate HTML elements, call existing functions, access variables defined in page. Script executes in page's security context (same origin policy applies). Runtime errors/exceptions are swallowed (silent failure due to put_Silent(VARIANT_TRUE) in creation). No return value captured - use for side-effect operations only (DOM manipulation, event triggers). For return values, use alternative methods (set hidden form field, call C++ callback via COM). Language parameter "JavaScript" specifies ECMAScript interpreter (JScript for IE). VBScript not supported. Multi-line scripts supported. Use cases: dynamic DOM updates, form manipulation, triggering page events, calling JavaScript functions defined in loaded HTML.