Icon

Goodbye AxWebBrowser

It wasn’t a perfect marriage, but we made it work. Your early death was documented here: IE7 Broke My AxWebBrowser!!!

I didn’t like how fat you were, between MSHTML and those two references I can never remember AxSHDocVw and SHDocVw. But you worked, and that’s all I ask.

To move over to the default WebBrowser component that comes with VS2005 I require the following things:

  1. Able to complete form items automatically.
  2. Able to click buttons on the page.
  3. Execute javascript functions on the page.
  4. Handles the new window and allows me to pop it into another web browser control.
  5. When doing #3, my ASP.NET session persists.

Ok, first we start with able to complete form items automatically.

WebBrowser1.Document.GetElementById(“txtUserName”).SetAttribute(“value”, “username”)
WebBrowser1.Document.GetElementById(“txtPassword”).SetAttribute(“value”, “password”)

CHECK!

Next, can we click a button?

WebBrowser1.Document.GetElementById(“btnLogin”).InvokeMember(“click”)

CHECK! So far much simpler than AxWebBrowser.

Now for the javascript function.

WebBrowser1.Document.InvokeScript(“myFunction”, New String() {“hello world”})

CHECK! Going great!

Here’s where we hit a snag. While WebBrowser has a NewWindow, it doesn’t give us any access to the URL. After some googling, I found someone who extended the component. Follow the directions posted by armoghan on 12/6/2007 found here.

So with that, you are given the event handler called NewWindowWithTarget, inside that event I place:

Dim frmWB As New Popup
frmWB.WebBrowser1.Navigate(e.Url)
frmWB.Show()
e.Cancel = True

And the session maintains!

And then my popups are handled! Except when I go to test it on some virtual machines, I find it does not work for Windows 2000. The author of the post did not indicate this, so I did some research. What he’s using is the NewWindow3 which was introduced with Windows XP SP2. If NewWindow3 fails, it moves on to NewWindow2 which pops up a separate IE process and loses the session. It works on IE6, IE7, or IE8 as long as you are Windows XP SP2 or higher. So that kills Windows 2000, and you can not even get IE7 for Windows 2k, so I’m screwed.

We had to make a tough call and we decided it was time to let go of Windows 2000 support. It’s been almost 9 years since it’s creation and 4 since Microsoft began to end the product life cycle. We’re able to lose the old AxWebBrowser and all the extra baggage. I hate to do it, but what choice do I have? Keep using IE6 for years?

Sigh. Check.

Category: Coding, VB.NET, Visual Studio

Tagged: , , , ,

One Response

  1. php tutorial says:

    Dude, thanks so much for this!!! I had to convert axwebbrowser to webbrowser control for an older vb project and I could not for the life of me understand why the compiler was complaining that invokescript and invokemember was not found as a member of the htmldocument class!

    Can you write a segment on event handling? For example, getting element reference from mouse clicks, actually move the mouse over a submit button (or any element for that matter).

    Thanks!
    Steve

Leave a Reply