Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Apr 2003
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    title and location of child window

    I need to open a new window and when it is closed return the values for location and title.

    Is it possible to detect the unLoad event of a child window, or do I have to continually check the location and title values of the child window from the parent using a while loop checking for its existence?

    pseudo code

    while (child not null) {
    var title = child.title;
    var location = child.location;
    }

    TIA

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    624
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try something like this, not tested
    Code:
    In the child
    
    onunload = function() {
    opener.foo(document.location, document.title)
    }
    
    in the parent
    
    function foo(document_location, document_title) {
    // do whatever
    }

  • #3
    New Coder
    Join Date
    Apr 2003
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I had thought of that but the problem is I can't place code in the new window as it needs to be freely navigable by the client, including using their favorites list so I can't even use frames to get around it.

    Any further suggestions??

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    624
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think your original idea will be the only way. I wouldn't use a while loop like that though, it will likely freeze the computer.

    Something like this. Open the window and give it a name then call check_win()
    Code:
    win_title = ''
    win_location = ''
    checking_win = false
    
    function check_win() {
    if (typeof checking_win == 'number') {
    clearTimeout(checking_win)
    }
    if (win_name) {
    win_title = win_name.document.title
    win_location = win_name.document.location
    checking_win = setTimeout('check_win()', 1000)
    } else {
    checking_win = false
    }
    }
    The checking_win thing just lets you use if (!checking_win) in other functions. Just FYI I haven't tested this nor tried it before.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    624
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, duh. You don't need if (!checking_win) you have if (win_name) for other functions
    Code:
    at the end of the opening function:
    
    checking_win = setTimeout('check_win()', 100)
    
    win_title = ''
    win_location = ''
    
    function check_win() {
    clearTimeout(checking_win)
    if (win_name) {
    win_title = win_name.document.title
    win_location = win_name.document.location
    checking_win = setTimeout('check_win()', 1000)
    }
    }

  • #6
    New Coder
    Join Date
    Apr 2003
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your last post is similar to what I came up with, though I had to use - win_name.document.location.href - to get any value for the location as without .href it returned nothing.

    Is it correct that this will only work as long as the child window's location stays within the same domain as the opener?

    It appears to throw up permissions errors if trying to access external urls - I assume this is a security feature?

    Thanx for your help

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Posts
    624
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was wondering about .href Thanks for the lesson.

    I think external urls could be a big issue. Unfortunately I also don't know what you can do about it.

    <edit>
    other than fail gracefully
    </edit>
    Last edited by Graeme Hackston; 07-07-2003 at 02:52 AM.

  • #8
    New Coder
    Join Date
    Apr 2003
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cheers for ur help

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Posts
    624
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No problem, to bad you couldn't make a go of it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •