WPF webbrowser anchor onclick event c# -
i loading page in webbrowser control & need capture event in control when anchor element clicked.
what trying execute piece of code, before link opens webpage dialog box.
this element on webpage
<a id="saveexpression" href="#end-result" class="buildertoolbar save" title="save expression"><span class="displace"></span></a>
i have tried couple of things far.
iserviceprovider serviceprovider = (iserviceprovider)_webbrowserctrl.document; guid serviceguid = sid_swebbrowserapp; guid iid = typeof(shdocvw.iwebbrowser2).guid; shdocvw.iwebbrowser2 mywebbrowser2 = (shdocvw.iwebbrowser2)serviceprovider.queryservice(ref serviceguid, ref iid); shdocvw.dwebbrowserevents_event wbevents = (shdocvw.dwebbrowserevents_event)mywebbrowser2; wbevents.newwindow += new shdocvw.dwebbrowserevents_newwindoweventhandler(onwebbrowsernewwindow);
the above seems fire when there 'newwindow', link opens webpage dialog box.
i have tried
mshtml.htmldocument doc; doc = (mshtml.htmldocument)mywebbrowser2.document; mshtml.htmldocumentevents2_event ievent; ievent = (mshtml.htmldocumentevents2_event)doc; ievent.onclick += new htmldocumentevents2_onclickeventhandler(ievent_onclick); bool ievent_onclick(ihtmleventobj pevtobj) { // code before webpage dialog box opened. return true; }
this captures every 'onclick' event, loses direction of click event does.
all want capture click on 1 particular button, perform action, before button opens webpage dialog. achieve onclick doesnt continue open dialog box, page has 'textarea' loses focus when onclick event triggered.
<textarea name="ctl00$contentforexpressions$txtexpression" id="ctl00_contentforexpressions_txtexpression" onkeyup="commonui.getposition(event);expressioncurrentstate.updatestatusflag();" onmouseup="commonui.getposition(event)" onpaste="return commonui.maxlengthpaste(this,"160");" class="expressionbuildertextbox" onchange="expressioncurrentstate.updatestatusflag()" onfocus="commonui.disabletoolitems()" type="text" onkeypress="commonui.disabletoolitems(this);" onmousedown="commonui.getposition(event)"></textarea>
is there neater or rather simpler way of achieving this? or missing something?
as long return true in ievent_onclick, should process event further. anyway, working solution is:
private bool ievent_onclick(ihtmleventobj pevtobj) { if (pevtobj.srcelement != null) { var parent = pevtobj.srcelement.parentelement; if (parent != null && parent.id == "saveexpression") { messagebox.show("bingo!"); return false; } } return true; }
Comments
Post a Comment