user2376149
user2376149

Reputation: 1

How to get link clicked event in geckofx18?

I am writing a tabbed web browser in Visual Basic and cannot figure out how to get the link address from a web page so I can open it in a new tab.

Upvotes: 0

Views: 1581

Answers (1)

Tom
Tom

Reputation: 6709

The following is an example of detecting if a link has been clicked on, preventing it navigating and doing somthing else with it. In this case showing a message box.

browser.DomClick += StopLinksNavigating;


/// <summary>
/// An example event handler for the DomClick event.
/// Prevents a link click from navigating.
/// </summary>
void StopLinksNavigating(object sender, GeckoDomEventArgs e)
{
    if (sender != null && e != null && e.Target != null && e.Target.TagName != null)
    {
        GeckoHtmlElement clicked = e.Target;
        // prevent clicking on Links from navigation to the
        if (clicked.TagName == "A")
        {
            e.Handled = true;
            MessageBox.Show(sender as IWin32Window, String.Format("You clicked on Link {0}", clicked.GetAttribute("href")));
        }

    }
}

Upvotes: 1

Related Questions