下面是我做的一个简单浏览器,输入网址之后老是跳转到默认浏览器,请高手帮我看下
private void GoBtn_Click(object sender, EventArgs e)
        {
            System.Object nullObject=0;
            string str=" ";
            System.Object nullObjStr =str;
            Cursor.Current=Cursors.WaitCursor;
            axWebBrowser1 .Navigate (textBox1 .Text ,ref nullObject ,ref nullObjStr,ref nullObjStr,ref nullObjStr);
            Cursor.Current =Cursors.Default;
        }
        private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
        {
            {
                    string strurl = webBrowser1.Document.ActiveElement.GetAttribute("href");
                    if (!strurl.Contains("://"))
                        strurl = "http://" + strurl;
                    this.webBrowser1.Url = new System.Uri(strurl, System.UriKind.Absolute);
                    e.Cancel = true;
            }
        }  private void toolBar1_ButtonClick(object sender,System .Windows .Forms . ToolBarButtonClickEventArgs e)
        {
            if (e.Button == toolBarButton1)
                axWebBrowser1.GoBack();
            if (e.Button == toolBarButton2)
                axWebBrowser1.GoForward();
            if (e.Button == toolBarButton3)
                axWebBrowser1.Refresh();
            if (e.Button == toolBarButton4)
                axWebBrowser1.GoHome();
            if (e.Button == toolBarButton5)
                axWebBrowser1.Stop();
        }

解决方案 »

  1.   

    你应该用的是com组件的浏览器,而不是.net类库自带的WebBrowser,所以你需要这样实现新开的窗口都用你自己的浏览器显示页面:
    axWebBrowser.RegisterAsBrowser=true;在webBrowser1_NewWindow事件中增加上面那一句,试试看就知道了
      

  2.   

    感谢你的回帖,可是按你说的做了,在webBrowser1_NewWindow下加上axWebBrowser.RegisterAsBrowser=true;结果还是跳转到默认浏览器。
    还有com组件的浏览器和.net类库自带的WebBrowser是什么啊,我是新手,不太懂,再帮我分析下吧