WebBrowser Control - How to send login session variables to popup windows

Hi all,

I am currently using WebBrowser control for VB6.0. When I navigate through a password protected user login website within the WebBrowser, whenever I click on a link that opens a new window - it ASKS for my username/password again (hence I believe the session variables are not sent to the new window). In fact, each time I stumble on a link that opens up a new window, it always asks for my login details again even though at the start I already specified them.

Is there a way I can make it so the webbrowser send the page's session variables into the new window in case it pops up?

Thank you for my urgent request.

Kind Regards,

Jess Richards
Energon Inc.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are you opening the new window in the NewWindow2 event of the browser?

How To Use the WebBrowser Control NewWindow2 Event
Or maybe you are allowing the WebBrowser to open its own pop-up windows? You can tell by looking to the pop-up, if it opens as a Internet Explorer window then the WebBrowser is handling it (and not you with the NewWindow2 event).

Anyway, I use the AxWebBrowser control in VB.NET 2003, and the pop-ups it open work Ok. The control behaves exactly as the Internet Explorer would.

By the way, does your Internet Explorer in that computer works well with that website? Do you have any pop-up blocker?
energonAuthor Commented:
Basically, when im loading a secured site within my WebBrowser...  it asks for my username/password first.. which is fine. But if you click on certain menu items which calls for a new popup, the new popup will ask for your username/password again. Yes, the popup open as a Internet Explorer window - is that ok?

If you use the normal IE 6.0 browser, even if you click on a link that leads to a popup, it would not ask for your login details again, as it remembers your session details.

I dont know why this is not the case for VB 6.0's WebBrowser control - i dont want people to have to key in their username/password more than once.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

>>Yes, the popup open as a Internet Explorer window - is that ok?

It opens it as a separate process which will not hold the session.  As stated, use the NewWindow2 event to handle popups...in its most simplistic form as an example:

(assuming you have a form named Form1 with a webbrowser control WebBrowser1)

Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
    Dim f As New Form1
    Set ppDisp = f.WebBrowser1.Object
End Sub

As I told you in VB.Net the AxWebBrowser just works well without any effort because it is exactly the same engine as Internet Explorer. More questions:

- Have you tried in another computer?
- Could it be that your IE is too old, or maybe too new for VB 6.0
- Do you really need to use VB 6.0?
- Have you tried with other protected website? For example I've tried with Yahoo Mail, I do a "Compose", press the "To:" link and the address book pops up ok as an IE window.
- Have you change any property to the WebBrowser different from its defaults?
energonAuthor Commented:
Ok it works if i open a NEW window altogether just for the webbrowser...

but what if i want the webbrowser to be within the main form window rather than a new form window?

basically when using AzraSound's script -

Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
    Dim f As New Form1
    Set ppDisp = f.WebBrowser1.Object
End Sub

f.Show will make the webbrowser show in a new window.. but i want it to be within my original form space. When i ran that function, it opens up a duplicate of my original form.

For example, my form name is MyMainForm

Thank you - sorry I am not too familiar with VB.
That is a little bit trickier.  The NewWindow2 event does not support continuing navigation in the same window.  Here is the workaround:

Dim WithEvents Web_V1 As SHDocVwCtl.WebBrowser_V1

Private Sub Form_Load()
    Set Web_V1 = WebBrowser1.Object
End Sub

Private Sub Web_V1_NewWindow(ByVal URL As String, ByVal Flags As Long, ByVal TargetFrameName As String, PostData As Variant, ByVal Headers As String, Processed As Boolean)
    Processed = True
    WebBrowser1.Navigate URL
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
energonAuthor Commented:
Great.. it works!!! Thank you... !
energonAuthor Commented:
One last question.. how do you add the "Back, Forward, Stop" toolbar within the WebBrowser window?

Thank you!

Kind Regards,

Jess Richards.
I just wanted to add the C# version of the code, as it took me another 45 minutes to figure it out after I found this page. Hope this helps someone else save some time!

private SHDocVw.WebBrowser_V1 Web_V1; //Interface to expose ActiveX methods
private void Form1_Load(object sender, EventArgs e)
    //Setup Web_V1 interface and register event handler
    Web_V1 = (SHDocVw.WebBrowser_V1)this.webBrowser1.ActiveXInstance;
    Web_V1.NewWindow += new SHDocVw.DWebBrowserEvents_NewWindowEventHandler(Web_V1_NewWindow);
private void Web_V1_NewWindow(string URL, int Flags, string TargetFrameName, ref object PostData,string Headers, ref bool Processed)
    Processed = true; //Stop event from being processed
    //Code to open in same window
    //Code to open in new window instead of same window
    //Form1 Popup = new Form1();

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.