Question

I use a webbrowser control in my application to get data from a specific web page. This web page won't work with the older IE because it specifically checks for the IE version. So I made a registry change that allows my application to work as IE 9 and everything is ok most of the time...

The problem is when a newwindow has to be opened. It won't display anything. I guess that the newwindow is acknowledged as IE 7 and I don't know how to make it disguise itself as IE9.

I also tried the other way round. I thought that if I intercepted the newwindow url then I could just send it to IE9 or open it in another instance of a webbrowser control. But the newwindow event only allows to cancel the event. You can't get any useful information out of it.

I believe that interop services is what I need but I know nothing about them.

So I've got two questions:
(1) Can I make the newwindow identify as IE9? (and how...)
(2) How can I get the newwindow url using interop services (or anything, I wouldn't care)?

Was it helpful?

Solution

It is quite strange (from my perspective) that the WebBrowser control doesn't surface the much-more-useful NewWindow3 event.

This CodeProject article describes a remarkably simple way to make it available.

OTHER TIPS

In the NewWindow event, assuming your first Wb control is named WB1 and the one you want to redirect to is WB2, do the following in your WB1 NW event.

Processed = True ' This cancels the current request.
WB2.Navigate URL ' This redirects it to the second WB2 control.

Otherwise, if you want to use the NW2 (NewWindow2) event instead of the NewWindow (NW) event, do this in the NW2 event of the WB1 control.

Set ppDisp = WB2.object ' Just swaps the objects around to redirect, don't need to issue a cancel.

Also, you can do this via BeforeNavigate2 (of WB1). But slightly different code.

Cancel = True ' Cancel Request.
WB2.Navigate2 URL ' Reissue it to WB2.

Now, as long as you control where it redirects to, you can get the new window URL easily, using WB2.LocationURL or Wb2.Document.URL if i am not mistaken.

Also, if you want to change the rendering engine to IE9 (even if IE9 is installed on your computer, WB control will use IE7 rendering engine for compatibility)... there are articles online and answers on SO (including some of my previous answers) which clarify how you can alter the registry to ensure the rendering engine used by the WB control is the same as that of the installed version (IE9), otherwise, it will always use IE7. And, if you have IE4, 5 or 6 installed on a machine, it will always use IE4 for the rendering engine. I think they update teh rendering version after ever 3-4 version changes. I'm assuming during version 10, WB control rendering version will be version 10 as well.

Let me know if you need more assistance with it and i've love to know how you got along and if this helped answer your question. All my examples are in VB6, but you can transform them easily.

Cheers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top