Call javascript function from browser control?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using the Browser control to display html that my application generates.
Some times i want a javascript to run when the html gets displayed in the
browser control, and sometimes i dont.

Is there a way to invoke a javascript function from the browser control? or
maybe inject some javascript vis the control's reference to the Document
object? I think i can do it with the Window object, but I have seem to
figout out how to get to the Window object from the browser control or the
Document object.

Any ideas?
 
Using the MSHTML library, cast the current document to an
IHTMLDocument2. If you are using the 2.0 browser, I think you have to
use browser.Document.DomDocument (untested):

IHTMLDocument2 doc = (IHTMLDocument2)browser.Document;

then use the execScript function off of parentWindow:

doc.parentWindow.execScript("myJSFunction();");

Regards,

Colin Neller
www.colinneller.com/blog
 
Back
Top