[Mono-winforms-list] WebBrowser - Calling Javascript

Andreia Gaita shana.ufie at gmail.com
Sat Nov 8 14:10:29 EST 2008

On Fri, Oct 31, 2008 at 4:37 PM, PsyTech <cmgambino at gmail.com> wrote:
> Hello,
> I was wondering if it was possible to make a javascript call to an item in
> the WebBrowser dom by having its IHTMLElement handle.  I couldn't find
> anything that was supported through the interfaces, but there might be
> another way I do not know about.

The HtmlDocument object has a InvokeScript method, but unfortunately
it only invokes existing javascript functions (it basically does
"scriptname()"). Mono.WebBrowser itself (the backend which the
webbrowser control uses) has no restrictions on what you can call, but
you have no access to that object when using winforms, and winforms
doesn't expose anything else that you might use.
If you want to hack it, though, you can call InvokeScript (script)
with what you want and it will work, as long as the last instruction
is a method that can be called with empty parenthesis... that's
because I'm just evaluating directly what I get on the parameter, so
if you send "a=1;b=2;alert", it will get evaluated as
eval("a=1;b=2;alert()"). Of course, this might be a bug on my part, I
need to check the behaviour on .net to make sure, so it might stop
working in the future... or it might not :P

andreia gaita
mono hacker

More information about the Mono-winforms-list mailing list