C# webBrowser中的链接在非ie浏览器中打开

来源:互联网 发布:淘宝宝贝人气排名 编辑:程序博客网 时间:2024/05/22 14:50

通过webBrowser的NewWindow事件,先取消 , 然后再用Process.Start 去打开一个网址 , 这个时候就是用默认浏览器打开。

private void webBrowser_NewWindow(object sender, System.ComponentModel.CancelEventArgs e){    e.Cancel = true;    var document = ((WebBrowser)sender).Document;    if (document != null)    {        if (document.ActiveElement != null)        {            string currentUri = document.ActiveElement.GetAttribute("href");            Help.ShowHelp(this, currentUri);//或者System.Diagnostics.Process.Start(currentUri);        }    }}

0 0
原创粉丝点击