I am loading a page in my webbrowser control & I need to capture an event in my control when an anchor element is clicked.
What i am trying to do is execute a piece of code, before the link opens the webpage dialog box.
this is the element on the webpage
<a id="saveExpression" href="#end-result" class="BuilderToolBar Save" title="Save Expression"><span class="displace"></span></a>
I have tried couple of things so 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 to fire only when there is a 'NewWindow', but the link opens some webpage dialog box.
I have also 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 the webpage dialog box is opened.
return true;
}
This captures every 'onclick' event, but then loses direction of what the click event actually does.
All i want to do is capture a click on one particular button, perform an action, before the button opens the webpage dialog. I could achieve this from the onclick but it doesnt continue to open the dialog box, the page also has a 'textarea' which loses focus when the onclick event is 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 a neater or rather a simpler way of achieving this? or am i missing something?