我正在使用Visual Basic 编写标签式网页浏览器,无法弄清楚如何从网页获取链接地址,以便我可以在新标签中打开它
答案 0 :(得分:1)
以下是检测链接是否已被点击,阻止其导航并使用其他方式执行其他操作的示例。在这种情况下显示一个消息框。
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")));
}
}
}