Click to See Complete Forum and Search --> : load parent window in mac


relish1227
04-29-2003, 10:59 AM
i have a link on a page that loads a new page into the parent window. if the parent window is closed, it should instead just load the url into a new window.

this works great on a pc... but try it on a mac and it doesn't work.

here's the code i'm using:

function load(file) {
if (window.opener.closed == false){
window.opener.location.href = file;
}else{
window.open(file,'xstar','');
}
}


i've tried putting in alerts to check the status of window.opener.closed -- if the opener still exists, i get an alert on a mac, like you'd expect. however, if the opener doesn't exist, i don't even get an alert. it's like, since the object is gone, it can't do anything.

any ideas on how to remedy the situation?

DaiWelsh
04-29-2003, 11:17 AM
Are you displaying all javascript errors and if so are you getting any errors when the opener is closed?

Just a guess, but you might try checking window.opener rather than window.opener.closed, it always struck me as odd that a window that had been closed still had an object in existence to check the closed status of, so perhaps this is windows specific and on mac the object no longer exists as would be more intuitive?

Dont have a mac to test on (I am glad to say).

Dai

relish1227
04-29-2003, 11:23 AM
thanks for the reply.

if you do an alert on window.opener -- in a pc it returns "[object]" and not a boolean.... do you know if there is some other way to check the existence of the opener? i already tried checking for window.opener == null.... was always false.

DaiWelsh
04-29-2003, 05:02 PM
Yes, window.opener should be an object (a window object to be precise), but I believe if you evaluate it in a boolean context it will work as 'is defined', so will return true if the object exists, false if it does not.

This method is used extensively in browser detection code. e.g. if(document.all) { alert('ie4+'); } which evaluates to false in NN4 rather than generating an error, even though document.all does not exist.

HTH,

Dai