skip to Main Content

When I open a child window from a parent window, I want it to reload after saving but sometimes the child window returns a blank page.

I want to reload the child window independent of the parent window action.

My code that reloads the window:

setTimeout(() => location.reload(true), 2000);

2

Answers


  1. This code will open a child window when the document is ready. The child window will have an onbeforeunload event listener that reloads the parent window when the child window is closed. This ensures that the parent window is always refreshed when the child window is closed.

    function openChildWindow() {
      var childWindow = window.open("child.html", "child", "width=500,height=400");
    
      // Add an event listener to the child window's save button.
      childWindow.document.getElementById("saveButton").addEventListener("click", function() {
        // Reload the child window.
        childWindow.location.reload(true);
      });
    }
    
    // Call the openChildWindow() function when the document is ready.
    document.addEventListener("DOMContentLoaded", openChildWindow);
    
    Login or Signup to reply.
  2. Do not use Firefox’s forceGet parameter as it is experimental and not widely supported.

    Pass true to force a reload bypassing the cache.

    Avoid using it if it’s unnecessary.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search