...

View Full Version : title and location of child window



nnichols
07-06-2003, 07:52 PM
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

Graeme Hackston
07-06-2003, 09:22 PM
try something like this, not tested


In the child

onunload = function() {
opener.foo(document.location, document.title)
}

in the parent

function foo(document_location, document_title) {
// do whatever
}

nnichols
07-07-2003, 12:27 AM
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??

Graeme Hackston
07-07-2003, 02:30 AM
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()


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.

Graeme Hackston
07-07-2003, 02:52 AM
Well, duh. You don't need if (!checking_win) you have if (win_name) for other functions


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)
}
}

nnichols
07-07-2003, 03:28 AM
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

Graeme Hackston
07-07-2003, 03:49 AM
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>

nnichols
07-07-2003, 03:53 AM
cheers for ur help

Graeme Hackston
07-07-2003, 03:56 AM
No problem, to bad you couldn't make a go of it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum