none
C# web browser question

    Question

  •  Hey there,

    Just a quick question. I have a web browser control added in C#,, just want to know how I can disable it so it cannot have a new window opened from it?

    I want to keep all browsing in my application and to never open up IE in its own window.

    Also is there a way to fire an event when the URL changes?

    My main aim of this is to create a way in my application to allow parents to block children from looking at certain WebPages in the browser window in my app.

    Alternatively, I could change the Internet explorer settings to add blocked sites to its list.. But I don't know how I’d go about that either.. I'd probably have to edit a dll somewhere or something.

    Thanks in advance

    Wednesday, September 10, 2008 5:00 AM

Answers

  •  

    Hello,

            You are using WebBrowser control, right?   The .NET Control or the Microsoft Web Browser?  

            Never mind, for both the two controls, I found the method to handle your issue.  J

            For .NET WebBrowser, I think you could use the following codes.   To disable the new windows, we could just handle the NewWindow event, and let the WebBrowser to open the new website.   And for the block website problem, we could just handle the Navigating event, and then let the WebBrowser open some safe website you defined.  

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


            For Microsoft Web Browser, the following codes I think might be useful.   The NewWindow3 event could disable opening the new windows.  And the event NavigateComplete2 could let us block some websites from opening.

            private void axWebBrowser1_NewWindow3(object sender, AxSHDocVw.DWebBrowserEvents2_NewWindow3Event e)  
            {  
                e.cancel = true;  
                axWebBrowser1.Navigate(e.bstrUrl);  
            }  
     
            private void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)  
            {  
                if (e.uRL.ToString().Equals(block.ToString()))  
                    axWebBrowser1.Navigate("some safe web page you defined");  
            } 

       
             Of course, if you have any more questions, please just let me know.

     

             Thanks,

     

    Best Regards,

    Lingzhi


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. http://forums.msdn.microsoft.com/en-US/csharpide/thread/8e9ed0d7-11ff-402a-8489-9b5f05eeb706 http://forums.msdn.microsoft.com/en-US/vssetup/thread/60424309-bd78-4ca2-b618-03c4a16123b6
    Friday, September 12, 2008 6:48 AM
    Moderator

All replies

  •  

    Hello,

            You are using WebBrowser control, right?   The .NET Control or the Microsoft Web Browser?  

            Never mind, for both the two controls, I found the method to handle your issue.  J

            For .NET WebBrowser, I think you could use the following codes.   To disable the new windows, we could just handle the NewWindow event, and let the WebBrowser to open the new website.   And for the block website problem, we could just handle the Navigating event, and then let the WebBrowser open some safe website you defined.  

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


            For Microsoft Web Browser, the following codes I think might be useful.   The NewWindow3 event could disable opening the new windows.  And the event NavigateComplete2 could let us block some websites from opening.

            private void axWebBrowser1_NewWindow3(object sender, AxSHDocVw.DWebBrowserEvents2_NewWindow3Event e)  
            {  
                e.cancel = true;  
                axWebBrowser1.Navigate(e.bstrUrl);  
            }  
     
            private void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)  
            {  
                if (e.uRL.ToString().Equals(block.ToString()))  
                    axWebBrowser1.Navigate("some safe web page you defined");  
            } 

       
             Of course, if you have any more questions, please just let me know.

     

             Thanks,

     

    Best Regards,

    Lingzhi


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. http://forums.msdn.microsoft.com/en-US/csharpide/thread/8e9ed0d7-11ff-402a-8489-9b5f05eeb706 http://forums.msdn.microsoft.com/en-US/vssetup/thread/60424309-bd78-4ca2-b618-03c4a16123b6
    Friday, September 12, 2008 6:48 AM
    Moderator
  • Hi Lingzhi,

    I suppose your answer works if one aleady knows a fair bit - which I don't, or at least not at this level.

    I have only just started really 'going public', say, and this requires quite a lot of research, which I want to keep in my Windows 7 system until I have completed it.

    Trouble is that, for a month or so, it appears that I may have some kind of spyware/data miner which nothing I've done can identify and remove.  So my last resort is to block the URL for (amch.questionmarket.com)

    What happens is that I am browsing when, at random(?), a blank window covers whatever it is I'm working on, with just a message "trying to close", so of course I close it.  But I do not know what "questionmarket" might have done meanwhile.  So for safety I want to block the URL, but cannot follow your advice in the form given.

    Thanks, Gerry Hiles

    Sunday, September 12, 2010 6:16 AM