C#WebBrowser:如何获取我点击的超链接的网址? [英] C# WebBrowser:how can I get the url of hyperlink I clicked?
本文介绍了C#WebBrowser:如何获取我点击的超链接的网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的webBrowser加载了一个页面,我想这样做:
我点击页面上的超链接,然后一个MessageBox显示我点击的超链接的网址。我赢了不要让页面转到url。事实上,我只想获得我点击的网址。
我怎样才能实现这个目标?
If my webBrowser has loaded a page,I want to do like this:
I click the hyperlink on the page,then a MessageBox show me the url of the hyperlink I clicked.And I won't let the page go to the url.In fact,I just want to get the url I clicked.
How can I achieve this?
推荐答案
查看这些链接;
C#中的Web浏览器 [ ^ ]
http:// www .c-sharpcorner.com /论坛/ ShowMessages.aspx?ThreadID = 46881 [ ^ ]
http://bytes.com/ topic / c-sharp / answers / 518523-web-browser-help-get-url-clicked-link [ ^ ]
你当您点击网络浏览器控件中的超链接时,可以使用导航事件来获取URL。
Have a look at these links;
Web Browser in C#[^]
http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=46881[^]
http://bytes.com/topic/c-sharp/answers/518523-web-browser-help-get-url-clicked-link[^]
You can use the navigating event to this to get url when you click the hyper link in your web broswer control.
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
string currentURl= e.Url.ToString());
}
private void webBrowser1_Navigating(object sender, NavigatingCancelEventArgs e)
{
string currentURl= e.Uri.ToString();
_addrBox.Text = currentURl;
}
这是我案例中的解决方案。 />
也许有人可以使用这个
this was the solution in my case.
maybe someone can use this
这篇关于C#WebBrowser:如何获取我点击的超链接的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文