Question webbrowser has to navigate in one window

Mrt

Member
Joined
May 18, 2010
Messages
16
Programming Experience
1-3
Hello,

I am making a webbrowser, can somebody tell me how to prevent my browser from opening new IE windows. Because what happens is, there are some links that will open new windows and therefore IE comes in place because it is set as default windows browser which I really don't want because my browser looks really bad if it opens links in another webbrowser.
I want it to be just a basic browser, it has only one window, and it should navigate within that window. This is because the browser is integrated in a bigger application only for some website applications that are related to this main application.

I am using VB.net 2008 Express Edition

Please advice, thanks
 
There actually is no way to prevent that using the .NET WebBrowser control. You will have to use the old Microsoft ActiveX web browser control, which the .NET control is a wrapper for, and handle its NewWindow2 event to cancel that new window.
 
This works perfect
VB.NET:
 Private Sub wb_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles wb.NewWindow
        e.Cancel = True
    End Sub
Thanks JohnH
Resolved
 
I'm a little confused. The documentation says:
The WebBrowser control opens a separate browser window when the appropriate overload of the Navigate method is called or when the user clicks the Open in New Window option of the browser shortcut menu when the mouse pointer hovers over a hyperlink.
I've seen many posts by others that say that NewWindow isn't raised when you just click a link that normally opens in a new window. I've never tested it myself but I took their word for it, which is why I suggested that what you wanted wasn't possible based on your description. Are you saying that NewWindow is raised for you when just clicking a link with a different target?
 
It worked for me for any kind of 'new window' initiated from that browsing session; context menu 'open in new', clicking anchors with target, clicking javascript window.opens stuff, automatic/ad popups - anything I could find that would otherwise cause a new window to open was blocked.
 
It worked for me for any kind of 'new window' initiated from that browsing session; context menu 'open in new', clicking anchors with target, clicking javascript window.opens stuff, automatic/ad popups - anything I could find that would otherwise cause a new window to open was blocked.

Hmmm... I've never actually had cause to use it myself so I was just going by what I'd read elsewhere. I wonder whether that behaviour was changed at some point. I might have to do a bit of my own testing to satisfy my curiosity.
 
Back
Top