Remote Window Control

Manage your windows. By assigning a variable to your `window.open` command, you retain a "handle" on that window, allowing you to manipulate it later from the main page.

Open the window, move it behind this one, then click Focus or Close.

Copy the Script

<script>
var myWindow; // Global variable to hold the reference

function openWin() {
  myWindow = window.open("", "RemoteWin", "width=300,height=200");
  myWindow.document.write("<p>I am the child window!</p>");
}

function closeWin() {
  if (myWindow && !myWindow.closed) {
    myWindow.close();
  } else {
    alert("Window is already closed or not open.");
  }
}

function focusWin() {
  if (myWindow && !myWindow.closed) {
    myWindow.focus();
  }
}
</script>

Frequently Asked Questions

The reference variable (myWindow) will be lost. JavaScript variables reset on page reload, so you will lose control of any previously opened windows.

No. The 'Same-Origin Policy' security feature prevents you from manipulating windows that have navigated to a different domain (e.g., if you opened Google.com).

Yes. As long as the window is on the same domain or blank, you can use 'myWindow.document.write()' to inject HTML content dynamically.