Click to See Complete Forum and Search --> : Can it be done? (Page unload question)
MGSteve
04-17-2003, 09:38 AM
I need to check the URL of the page being loaded when a page is unloaded, if its not on my site, I want to show a 'goodbye' popup.
Question is, can this be done? I've spent most of the day pulling my hair out as I can't seem to find a way to detect the URL of the page being loaded in the unload function.
Please say someone knows how to do it.
Cheers ppl.
Regards
Steve Childs.
tim_gor
04-17-2003, 10:21 AM
Well it CAN be done... and I can think of a pretty crude way of doing it:
As far as I can tell (and I hope someone can enlighten me if I'm wrong) -- a window can't tell what location it's loading when its onunload event is invoked.
However, what you could do, is that everytime you're page "unloads", it could open another window
i.e.
function unloadHandler(){
window.open("pageChecker.htm","NewWindowName");
}
window.onunload = unloadHandler;
You could then put some script in pageChecker.htm which tests the variable:
opener.location.href
in some sensible manner to see if it belonged to one of your pages, and if so popping up a GoodBye dialogue, then closing itself.
I suppose to extra clever, you could even open the new window in some place hidden on the screen -- e.g. really far down below the screen or to the right of it.
I can't think of any other way of doing it at the moment...