Jeff Sanders Technical Blog

I am a Microsoft employee that has worked on all aspects of the Web Stack for a long time. I hope these blogs are useful to you! Use this information at your own risk.


<< Go Back

Internet Explorer Webbrowser Control Loses State When Jscript Performs A Call To Window Open

- 04 May 2007

Session state for a web site is often stored in cookies.  If you use the WebBrowser control in an program and the target website responds to an action with a call to Window.Open, then mysteriously the cookies for that site are not transmitted with the request.

**Cause: 
** Window.Open creates a window using the IExplore.exe process since it does not have a parent window handle.  You cannot share cookies across processes.

Correct methods to use:

**
1.  Change the jscript**

You can change the jscript to use the parent application window handle and that will host that window in your application’s process. 

function MyShowModal()
{
                var args = new Object;
                args.window = window;
                showModalDialog(“modal.asp”, args);
}

2.  Your application can host the New Window

If your application goes to web sites that are not under your control, you handle the NewWindow2 event from the browser control as covered in these KB articles:

How To Use the WebBrowser Control NewWindow2 Event  
http://support.microsoft.com/kb/184876/EN-US/

How to use the WebBrowser control NewWindow2 event in Visual Basic .NET .Net Version: http://support.microsoft.com/kb/311282/EN-US/

How to use the WebBrowser control NewWindow2 event in Visual C# .NET or in Visual C# 2005
http://support.microsoft.com/kb/815714

Related article:
How to maintain the ASP.NET session state
http://support.microsoft.com/kb/932474<p mce_keep="true"> </p>

<< Go Back