VB.NET Tips / Tricks / Examples and Help

VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)


Thu, Aug 7 2008

Downloads: 7,887
File size: 21.4kB
Views: 42,404
VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)

This is sample code written in VB.NET using Visual Studio 2005 and targetting .NET framework 2.0.

The standard built in Webbrowser control is missing many key features of the unmanaged COM based control. This is likely due to the framework's need to work against versions of Internet Explorer from 5.x all the way up through 7 and on. However you can implement the missing features yourself by extending the existing browser control, and syncing up the events you want to know about, and firing off code when these events occur.

The 2 events this example covers are:

  • NavigateError - When a navigation error occurs, for any reason, the managed browser gives no indication via an event that this has happened. Implementing this event back into the control allows you to know when navigation has failed.
  • NewWindow2 - Allows you to specify another browser instance/window in your application to house a popup when a newwindow is being created either via javascript, or a regular anchor tag with a target set to _blank. The worst part about the managed browser control as it stands now in the framework, is that new windows are actually generated in a new instance of Internet Explorer. This means session data does not persist across popups, which will make many websites simply not work (or force you to sign in again on every popup window)

You can see this for yourself, by visiting a testing page I made. If you visit this page using the standard .NET webbrowser control, and click the link, you will see the session data is not carried over to the popup, however in my extended browser, the session data will persist, because the popup window is created as part of your application.

The test page is here: http://zerosandtheone.com/public_files/asp/sessiontest/

This also means you can customize the look of the popup window, which is pretty cool. Perhaps you want to make it look different, or add other controls to it.

Comments

Murty wrote re: VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)
on Wed, Sep 3 2008 10:03 AM
Thanks dude, i need this to complete my project
John Walton wrote re: VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)
on Wed, Dec 17 2008 3:01 AM
This is brilliant. Not being able to upgrade what I did in VB6 was a real pain till I found this. Thanks Matthew.
bubu wrote re: VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)
on Mon, Dec 29 2008 1:06 AM
very good,that is what I need,thank you!!!
John wrote re: VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)
on Tue, Jan 13 2009 11:18 AM
I've been looking everywhere for this. Thanks!
Lectere wrote re: VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)
on Sat, Jan 24 2009 7:42 AM
Very nice!, Thanks a lot!
ssc707 wrote re: VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)
on Wed, Jan 28 2009 8:01 PM
This works great....but its not always working when using javascript open functions (or close function, not closing the new window) Also, when the javascript function sets, height and width, the new window does not take them on.... try the examples of javascript new windows from here:- http://www.quirksmode.org/js/popup.html Any thoughts on how to go about it ?
bonejack wrote re: VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)
on Tue, Feb 17 2009 8:37 PM
I have the same question as ssc707. Anyone know how to get get java open and close functions to work?
John wrote re: VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)
on Sat, Feb 21 2009 3:06 PM
Well, it would've been great for me, but I can't get it to work in VB 2008 Express. It shows an error after conversion.
Mike wrote re: VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)
on Mon, Aug 24 2009 10:01 PM
I'm having the same issues as John is having with 2008 Express... :>(
Matthew Kleinwaks wrote re: VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)
on Thu, Aug 27 2009 4:36 PM
What specific errors do you get?
ikky wrote re: VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)
on Sun, Aug 30 2009 3:00 PM
This is definately down the path i need, but i seems to be holding a little more then it should. I have my reports opening in popups. Before you code it would work at all, not the first report will pop up normally, but all pop ups after that display the same information as the original first. It is not loading the new reports. Is there a setting i need to clear once the page is loaded so that i loads each popup from scratch?
ikky wrote re: VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)
on Sun, Aug 30 2009 9:59 PM
I tested you logic and it seems to work OK for the first window, but after that it bring up every additional window with the information from the first window. Any ideas how to get around this?
Matthew Kleinwaks wrote re: VB.NET Extended Webbrowser Control (NewWindow2 and NavigateError events)
on Fri, Sep 25 2009 5:48 PM
ikky, can you provide a little more detail into the issue you are having?


© 2014 - ZerosAndTheOne.com - Hosting by Orcsweb (http://www.orcsweb.com/)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems