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.
The original Open, Close and Move To controls are preserved in the demo.
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.
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
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.