Hello ,


I am having a problem where the parent window is controlling a popup child window, and when the parent window refreshes or changes a query, the child window var gets nulled, forcing the child to refresh.

What is a way to solve this by still controlling a child after parent refresh without using frames.

I have read about PDOM Persistant Object Document Model. But I just don't understand how to use it in this scenario. Advice with an example would be much appreciated!

Thank you.

Dani AI

Generated

Short version: the in-memory child variable in the parent is lost on a reload, but you can reliably reattach to an already-open popup and keep two-way comms by using a persistent popup name plus message-based communication. This addresses ’s issue and expands on the hints from and : you don’t need frames, and you don’t need a nonstandard "PDOM" hack.

A practical pattern:

  • Give the popup a fixed name and, on parent load, call window.open('', popupName) to get a handle to an existing window (or create it if none exists).
  • Use postMessage (or BroadcastChannel or localStorage events) to send state and commands between the pages instead of relying on long-lived JS variables.
  • Let the child call window.opener for simple callbacks when same-origin, but use postMessage for robust cross-origin-safe messaging.

Example parent/child skeletons:

Parent (on load):

var popupName = 'myPopup';
var child = window.open('', popupName);
if (!child || child.closed) {
  child = window.open('/child.html', popupName, 'width=600,height=400');
} else {
  child.postMessage({type:'reconnect', state:/*current state*/}, location.origin);
}

Child (listening):

window.addEventListener('message', function(e){
  if (e.origin !== location.origin) return;
  if (e.data && e.data.type === 'reconnect') {
    // apply state
  }
});

Notes and cautions: direct DOM/JS access requires same-origin; otherwise postMessage is the safe channel. Pop‑up blockers and user-gesture requirements can affect when you may open windows. Avoid rel="noopener" if you need window.opener. For API details see window.open, window.opener, postMessage and BroadcastChannel.

Recommended Answers

All 3 Replies

I don't believe this is possible. As you say, once you close the parent, the reference to it is nulled. I've never heard of "PDOM".

Without seeing the code it is hard to say...

Am I correct in assuming the parent window calls a child window of the same name every time it is refreshed or the query changes?

Just a shot in the dark...

You could try having the parent window assign a different name to the popup window every time.

Wouldn't that stop the parent window from resetting the variables of the child window that is already open?

Yes, it would. What you no longer have, though, is a valid reference within the child window, to the original parent window. If the goal is for the child window to make further reference/changes to the parent window after the parent has refreshed, I think that's not possible.

If the goal is for the refreshed parent window to not re-generate the child window, then yep... make script changes in your parent window to check to see if there is already a child window. If so, don't re-create it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.