views:

250

answers:

2

We have a product that has both a winforms and a web client, and are providing the users a way to launch into another company asset (a web application). We need to make sure that the user only ever has one instance of the other web application open in a browser (or at least that we've opened for them). We accomplished this (sort of) by doing the following...

In the winforms client, we have a hidden WebBrowser control that, when the user clicks the button to launch the other app, we write a small HTML page into the DocumentText property that contains:

window.open('http://othersiteurl', '**sitename**').focus();

In our web client when the user clicks on the same button we do something similar:

window.open('http://othersiteurl', '**sitename**');

From only one client or the other this works surprisingly well. Where things get sticky and weird is when you try accessing it from both clients. If you launch the other product from the winforms app first, it launches a new window, and any subsequent launches of the product from either client load in the instance that's already open. But if you do it the other way around, and start from the web client, the first instance launches in a new tab in the same window, but then every launch from the winforms client goes to a new window!

I'm using the same value for the 'name' parameter of the window.open in both clients. It's bizarre to see it work so horribly different. Can anyone explain how the 'name' parameter is scoped in IE? (yes, this is IE-only...the WebBrowser control hosts IE, and our product is IE-only) When launching from the winforms client first it seems to be global to all open instances, but the other way around makes it seem very much the opposite.

Any ideas?

A: 

Have you tried window.createPopup? Dunno if it would work any better, but if you don't need the "chrome" it might be worth a shot. For more info check out the MSDN: http://msdn.microsoft.com/en-us/library/ms537638(VS.85).aspx

machineghost
A: 

Under IE7, and prior versions as well to my knowledge, the name parameters is scoped to a particular instance of the IE process. Typically, starting IE manually creates a new process. Any windows that are created via js or even clicking the "New Window" button within IE, creates a new window that is still running under the current process. Under this condition, the name is in scope across these windows.

When you have a desktop application spawn an instance in the way you mention, it is opened under a new process. Depending on the framework (.NET, etc) it may reuse the process once it has a handle to the first, or it may create a new process for each call. It sounds like, from your initial testing, that the first is the case, where the application will reuse the process.

That being said, I am not sure what kind of process you may have to implement to check for the name "cross-process". One option, depending on what kind of control you have over the web application they are accessing, could be to have the server keep track of a list of user to session ids and when a second entry shows up for a user, that means they have a second browser open, and handle appropriately from there.

Mike Clark