Web Analytics Made Easy -
StatCounter Capture Opener URL - CodingForum

Announcement

Collapse
No announcement yet.

Capture Opener URL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Capture Opener URL

    Hello!

    I have a very simple HTML page that contains a button that does a window.open to access an asp on our webserver. In that asp I'm trying to capture the URL of the opener window. I then want to search through that URL for a specific string.

    Can someone give me some tips on how to accomplish this? I'm very new to Javascript so I'm not sure how to actually capture the window.opener URL. I've tried just assigning the window.opener.location to a String variable but it doesn't work.

    Here is the code I'm using:

    if (window.opener && !window.opener.closed)
    {
    window.alert('Opener Exists');

    var windowLoc = new String window.opener.location.toString());

    window.alert(windowLoc);

    }
    else

    {
    window.alert('no opener exists');

    }

  • #2
    Hi, have you tried
    Code:
    window.opener.document.location
    ?

    http://www.webreference.com/js/tutorial1/opener.html

    EDIT Heres your example, refined a little:

    Code:
    <script type="text/javascript">
    Parent = window.opener ;
    
    if (Parent && !Parent.closed)
    	{
    var windowLoc = unescape(Parent.document.location) ;
    alert('Opener Exists!\n' +
    windowLoc) ;
    	}
    else alert('No Parent Window exists');
    
    </script>
    This is in the window to be opened. A few points:
    1. You don't always have to use window.alert, the window object tends to be the most high level object available, your web browser assumes it belongs to it. [I think your web browser actually provides the 'window' object]
    2. You don't always have to use 'new String()' - anything enclosed in " or ' is a string


    I'm sure others might add to this or correct it, so stand by.
    Last edited by vkidv; Aug 3, 2005, 03:20 PM.
    Regards
    VKiDV

    Comment

    Working...
    X