Suppose we have a website in which you click on a button, and that opens a popup (child) window using JavaScript. So let’s call the parent A and the popup P. In the source of A, we’d see something like this:
<script type="text/javascript">
P = window.open('P.html', 'P');
</script>
So as long as A is open, we can interact with P in JavaScript using the P variable. However, when I click on a link in A to go to B.html, I lose all the variables. Yet my popup window is still open, so I wonder if there’s any way I can link the two back together. Is there any way I can manipulate P from within B? Thanks much.
Well I figured out that, to my pleasant surprise, the answer is YES. Mohammad’s solution of using
window.topwas not correct; when I try to accesswindow.topfrom within P, that just returns a reference to P itself. RobG’s answer just kind of missed the point.I found that if I do this periodically from within P, everything works:
This way, even when I navigate the parent window from A to B, B will still be updated with a window reference to P and once that’s established the two windows can then communicate freely with each other again.