有人知道如何在WPF WebBrowser控件中捕获单击链接吗?
当点击链接时,我需要在页面导航之前获得链接目标。
任何投入都非常感谢!
My解决方案在代码中是为简单链接而提出的,这将通过以下代码实现:
private void webBrowser1_Navigating(object sender, NavigatingCancelEventArgs e)
{
//prefix must be lowercase (ssrs conforms to web-standards and makes things lowercase)
string myPrefix = "http://myPrefix";
//check if target starts with the prefix
if (e.Uri.AbsoluteUri.StartsWith(myPrefix))
{
//cancel Navigation
e.Cancel = true;
}
}谢谢你在这件事上伤害了我。
发布于 2010-07-15 13:06:42
您可以将事件处理程序附加到导航事件。解压链接,在导航页之前执行逻辑。
干杯。
发布于 2016-03-28 18:24:12
控制在WebBrowser导航事件处理程序中的单击。您可以在Xal或构造函数中创建此函数,并使用以下方法:
private void webBrowser_Navigating(object sender, NavigatingCancelEventArgs e)
{
// The WebBrowser control is checking the Uri
if (e.Uri.ToString() != "Place your url string here") //ex: "http://stackoverflow.com"
{
// Uri is not the same so it cancels the process
e.Cancel = true;
}
}https://stackoverflow.com/questions/3255726
复制相似问题