How to know whether WebBrowser navigating a error page?

前端 未结 2 1395
逝去的感伤
逝去的感伤 2021-01-18 18:12

for example, we navigating to http://www.ggg111.com, it\'s a error URL. but in WebBrowser it display a error page with this:

The webpage cannot be found 
 HTTP 40         


        
2条回答
  •  轮回少年
    2021-01-18 18:33

    not sure about this but,.... try it,...

    string check = webBrowser1.DocumentText;
            if (check.IndexOf("The webpage cannot be found") > 1)
            {
                MessageBox.Show("ERROR OCCURED");
                //what else you want to do, do here!!!
            } 
    

    this will search for given text and if found will execute further code

提交回复
热议问题