简体   繁体   中英

GeckoFX - alternative of WebBrowser control's “RaiseEvent” or “InvokeMember”

In Microsoft webbrowser control it is possible to do something like that:

webBrowser1.Document .GetElementsByTagName("select")[4] .RaiseEvent("onchange");

which will programmatically raise the event on the webpage.

Is it possible to do so with GeckoFX? I did not find any method that would work this way with HTML elements (select for example)

Cheers

After a couple of days worth of searching, I have found out how this works

First, create the 'name' of the event

Then, create the event itself

Then initialize this event

Finally, dispatch this event on the target. For example:

nsAStringBase changeEvent = (nsAStringBase)new nsAString("change");
var ev = browser.Document.CreateEvent("HTMLEvents");
ev.DomEvent.InitEvent(changeEvent, false, false);
myElement.GetEventTarget().DispatchEvent(ev);

Works like a charm, hope this will be useful for someone in the future.

Bartosz

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM