It depends on how you opened the window - if you used 'target=_new' then HTTP_REFERER should be OK, but if you used a Javascript 'window.open', then I think the only way is by using 'window.opener.location'.
Good luck.
Comment on Re: getting referer from a popup window