简体   繁体   English

GeckoFX - WebBrowser控件的“RaiseEvent”或“InvokeMember”的替代品

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

In Microsoft webbrowser control it is possible to do something like that: 在Microsoft webbrowser控件中,可以执行以下操作:

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

which will programmatically raise the event on the webpage. 它将以编程方式在网页上引发事件。

Is it possible to do so with GeckoFX? 是否可以使用GeckoFX这样做? I did not find any method that would work this way with HTML elements (select for example) 我没有找到任何可以通过这种方式使用HTML元素的方法(例如选择)

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 巴尔托什

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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