views:

442

answers:

5

Is there a way to determine in the child page's code behind that is was opened by the window.open() javascript command from the parent page?

The pop-up page contains a user control that is used by other pages that are not spawned from a window.open() command and I want to dynamically add functionality to close the page after the user has completed their task in the child page.

It is an ASP.NET C# 3.5 application.

+5  A: 

Can you pass through a flag in the querystring which will indicate where the window was spawned from?

Galwegian
I created a property on the user conrtrol to indicate if it contained with a page that is spawned by a pop up window
Michael Kniskern
A: 

Might be wrong, but I don't think there's a simple direct way to do this. You could always try to identify it from a distinct url, e.g. "MyChildForm.aspx?from=winopen"

--Edit-- Beaten to it by Galwegian

ZombieSheep
+2  A: 

in javascript you can check if window.opener is null

Sergio
A: 

You could add some javascript in the usercontrol to test whether window.opener is non-null and on that basis hide or show the close page UI.

AnthonyWJones
+1  A: 

The request for the child window will probably have an HTTP Referer (referrer) header that points to the parent page. You could check that at the backend or check window.opener on client side.

Ates Goral
I tried this solution and it threw a NullReferenceException when I tried to get the Request.UrlReferrer.AbsolutePath
Michael Kniskern