Window Reference After Parent Page Changed
Solution 1:
I can think of two possible ways that might be worth trying...
Firstly, you could approach this by letting the child window talk to the parent window rather than the parent to the child. Whilst the parent window will lose the reference to the child when the page transitions the child should still be able to get back to the new page (as long as it is still on the same domain) via window.opener. The child could use set interval to access the opening window and set a 'still open' status. You would have to code it in such a way as to be able to handle not having a document during the transition load but it would work. Code would be roughly as below but you could refine this by handling the load and unload events of the parent by the child and only running the timer between transitions.
Parent Window (all pages)
var childStatus = "unknown";
Child Window
var timerHandler;
funciton ChildCallBack()
{
try
{
window.opener.childStatus = "open";
}
catch(e)
{
}
}
timerHandler = window.setInterval(ChildCallBack, 100);
functionwindow_onclose()
{
try
{
window.clearInterval(timerHandler);
window.opener.childStatus = "closed";
}
catch(e)
{
}
}
window.onclose = window_onclose;
Secondly, and ideally as a last resort, the other, quite horrible, alternative is to use an iframe. Place your transitioning page within an iframe so the actual main page doesn't change and so can maintain a reference to the child. The iframe could be sufficiently large as to appear like a full page. It is a nasty hack like solution but should also work.
Solution 2:
Try to use window name, the second parameter of the window.open method, as a name of variable:
win = window.open("xxx.html", "mywin");
And then when you want to close window:
mywin.close();
Post a Comment for "Window Reference After Parent Page Changed"