window.moveTo(): Move a Window to X, Y Coordinates

window.moveTo() requests an absolute screen position for a browser window. The first argument is the horizontal X coordinate and the second is the vertical Y coordinate, measured in CSS pixels.

window.moveTo(x, y);

Unlike moveBy(), which moves relative to the current position, moveTo() requests a specific screen coordinate.

On this page

Move a child window to x=300, y=300 Top ↑

The original Open, Close and Move To controls are preserved in the demo.

DEMO of Move To

Complete source Top ↑

The complete working page is shown in one block so users can copy it directly.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demo of moveTo() to position a child window</title>
</head>
<body>
<button type="button" id="openBtn">Open</button>
<button type="button" id="closeBtn">Close</button>
<button type="button" id="moveBtn">Move To</button>
<p id="demoStatus" aria-live="polite"></p>
<script>
let tm = null;

function showStatus(message) {
  document.getElementById("demoStatus").textContent = message;
}

function to_open() {
  tm = window.open(
    "moveby-child.htm",
    "Ratting",
    "width=250,height=150,left=150,top=200,status=0,resizable=yes"
  );
  showStatus(tm ? "Child window opened." : "Popup blocked. Allow popups and try again.");
}

function to_close() {
  if (tm && !tm.closed) tm.close();
  else showStatus("Open the child window first.");
}

function to_moveTo() {
  if (!tm || tm.closed) {
    showStatus("Open the child window first.");
    return;
  }
  tm.moveTo(300, 300);
  tm.focus();
  showStatus("Requested position: x=300, y=300.");
}

document.getElementById("openBtn").addEventListener("click", to_open);
document.getElementById("closeBtn").addEventListener("click", to_close);
document.getElementById("moveBtn").addEventListener("click", to_moveTo);
</script>
</body>
</html>

The child page used by this example is the same moveby-child.htm helper documented on the moveBy tutorial.

When moveTo() may be ignored Top ↑

Browser restriction: an ordinary tab generally cannot reposition itself. Browsers typically restrict moveTo() to windows created by window.open(), and movement can still be ignored on mobile or some desktop/window-manager environments.

Do not use window positioning as part of a responsive page layout. Use CSS layout techniques for content inside a page.

Window Object Window resizeTo Redirect Page




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer