Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Hosting and Reuse
MSHTML Reference
IHTMLWindow2
 execScript Method
IHTMLWindow2::execScript Method

Executes the specified script in the provided language.

Syntax

HRESULT execScript(      
    BSTR code,     BSTR language,     VARIANT *pvarRet );

Parameters

code
[in] BSTR that specifies the code to be executed.
language
[in] BSTR that specifies the language in which the code is executed. The language defaults to Microsoft JScript.
pvarRet
[out, retval] Address of a VARIANT of type VT_EMPTY. This method always returns VT_EMPTY.

Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

Script executed through the IHTMLWindow2::execScript method can access all global variables available to the calling script. This can be useful when you want the functionality of another scripting language that would not otherwise be available in JScript, such as the Microsoft Visual Basic Scripting Edition (VBScript) MsgBox function.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
"specified cast not valid"      Diablo22   |   Edit   |   Show History
I have this exception thrown out when I execute the following:
InternetExplorer browser = new InternetExplorerClass();
mshtml.IHTMLDocument2 doc2 = (IHTMLDocument2)browser .Document ;
if (doc2 != null)
{
IHTMLWindow2 win = doc2.parentWindow;

win.execScript("alert('hello')", "javascript");

}
Tags What's this?: Add a tag
Flag as ContentBug
Navigate() first?      Bharghava, Vyas   |   Edit   |   Show History

I'm not sure if you can say "new InternetExplorerClass()" and immediately expect the browser.Document to contain something.
You may need to Navigate() to a valid URL first.

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker