locked
How do I block specific URLs in the WebBrowser?

Answers

  • If you want to block specific URLs in the WebBrowser, you can use the event handler to set limits on WebBrowser Navigating events.  When the WebBrowserNavigatingEventArgs.Url equals the URL you want to block, we can set the WebBrowserNavigatingEventArgs.Cancel to true, so that the navigating action of the WebBrowser will be canceled.  

    Here is the code sample:

     

    private void webBrowser1_Navigating(object sender,  WebBrowserNavigatingEventArgs e)
    {
         if (e.Url.Equals("http://www.microsoft.com"))
         {
             e.Cancel = true;
         }
    }
    
    

     

    Related thread:
    http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/c0f3b211-4aba-4c7d-9a62-1f5b24caf801

     

    For more FAQ about Visual C# General, please see Visual C# General FAQ

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

     

    Wednesday, April 08, 2009 3:25 AM