Call javascript function from browser control?

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?
 
C

Colin Neller

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top