Anchor Click

Add-in Express™ Support Service
That's what is more important than anything else

Anchor Click
 
Georges DEME




Posts: 18
Joined: 2017-03-07
Hi,

How to get the event click of an Anchor like this <a>FWD</a> inside a Table.

<td><a class="k-button k-button-icontext k-grid-Forward" href="/Exceptions/Exceptions?Item.ItemSkuNo=234" name="Forward" style="min-width: 28px; text-align:center;"><span></span>FWD</a></td>

I want if the user click on FWD , I display a MessageBox.Show("FWD Clicked").

Thanks!
Georges
Posted 25 Mar, 2017 23:46:31 Top
Andrei Smolin


Add-in Express team


Posts: 18818
Joined: 2006-05-11
Hello Georges,

Put an ADXIEHtmlDocEvents component onto the module, set the SupportedEvents property to Anchors, and handle the OnClick event. Also, check section Step #10. Intercepting HTML Events, see the PDF file in the folder {Add-in Express}\Docs on your development PC.


Andrei Smolin
Add-in Express Team Leader
Posted 27 Mar, 2017 04:59:19 Top
Georges DEME




Posts: 18
Joined: 2017-03-07
Hi Andrei,

I set the SupportedEvents property to Anchors like this.

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.adxiehtmlDocEvents1 = new AddinExpress.IE.ADXIEHTMLDocEvents(this.components);
this.adxiehtmlDocEvents1.SupportedEvents = ADXIEHTMLSupportedEvents.seAnchors;
//
// adxiehtmlDocEvents1
//
this.adxiehtmlDocEvents1.OnClick += new AddinExpress.IE.ADXIEHTMLEventObjectEx_EventHandler(this.adxiehtmlDocEvents1_OnClick);
//
// IEModule
//
this.HandleShortcuts = true;
this.LoadInMainProcess = false;
this.ModuleName = "ESGextension";
// this.WindowStateChanged += new AddinExpress.IE.ADXIEWindowStateChanged_EventHandler(this.IEModule_WindowStateChanged);

}
-----------------------
private void adxiehtmlDocEvents1_OnClick(object sender, object eventObject, ADXCancelEventArgs e)
{
if (HTMLDocument.url == "https://pbcrossborder.xxx/Exceptions/Exceptions")
{
mshtml.IHTMLEventObj2 obj = eventObject as mshtml.IHTMLEventObj2;
if (obj != null)
{
mshtml.IHTMLElement elem =
this.HTMLDocument.elementFromPoint(obj.x, obj.y);
if (elem != null)
{
//mshtml.HTMLInputElement input = elem as mshtml.HTMLInputElement;
mshtml.HTMLAnchorElement anchor = elem as mshtml.HTMLAnchorElement;
MessageBox.Show(anchor.name);
if (anchor.name == "Forward")
{
MessageBox.Show("Forward clicked");
}


}



But still the Anchor is not firing.

Georges
Thanks!
Posted 27 Mar, 2017 12:18:26 Top
Georges DEME




Posts: 18
Joined: 2017-03-07
if (HTMLDocument.url == "https://ssborder.com/Exceptions/Exceptions")
{

mshtml.IHTMLEventObj2 eventObj = eventObject as mshtml.IHTMLEventObj2;

mshtml.IHTMLElement elems = this.HTMLDocument.elementFromPoint(eventObj.x, eventObj.y);

mshtml.HTMLAnchorElement anch = elems as mshtml.HTMLAnchorElement;

if (eventObj != null && eventObj.srcElement != null)
{
if (eventObj.srcElement is mshtml.IHTMLAnchorElement2)
{
if (anch.name == "Forward")
{
MessageBox.Show("FWD BUTTON clicked");
}
}
}
}



How to get the Anchor Name value ?


Thanks
Georges
Posted 27 Mar, 2017 15:50:01 Top
Andrei Smolin


Add-in Express team


Posts: 18818
Joined: 2006-05-11
Hello Georges,

Does the code below work for you?

private void adxiehtmlDocEvents1_OnClick(object sender, object eventObject, ADXCancelEventArgs e) {
    mshtml.IHTMLEventObj2 eventObj  = eventObject as mshtml.IHTMLEventObj2;
    if (eventObj  != null) {
        mshtml.IHTMLElement elem =
            this.HTMLDocument.elementFromPoint(eventObj.x, eventObj.y);

        if (elem != null) {
            System.Diagnostics.Debug.WriteLine("!!! elem != null");
            MessageBox.Show(elem.tagName);
            mshtml.IHTMLElement sourceElem = eventObj.srcElement;
            if (eventObj != null && sourceElem != null) {
                System.Diagnostics.Debug.WriteLine("!!! eventObj != null");
                if (sourceElem is mshtml.IHTMLAnchorElement2) {
                    System.Diagnostics.Debug.WriteLine("!!! IHTMLAnchorElement2");
                    mshtml.HTMLAnchorElement anch = sourceElem as mshtml.HTMLAnchorElement;
                    System.Diagnostics.Debug.WriteLine("!!! anch.name=" + anch.name);
                    if (anch.name == "Forward") {
                        MessageBox.Show("FWD BUTTON clicked");
                    }
                }
            }
        }
    }
}



Andrei Smolin
Add-in Express Team Leader
Posted 28 Mar, 2017 07:50:02 Top
Georges DEME




Posts: 18
Joined: 2017-03-07
Thanks Andrei is working now.

Georges
Posted 28 Mar, 2017 09:21:01 Top
Andrei Smolin


Add-in Express team


Posts: 18818
Joined: 2006-05-11
Welcome.


Andrei Smolin
Add-in Express Team Leader
Posted 28 Mar, 2017 09:24:05 Top