JavaScript window.moveTo() Method

You are Here:

JavaScript window.moveTo() Method

The window.moveTo() method moves the current window to the specified coordinates.

Note: Unlike window.moveBy(), this method moves the window to an absolute location.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <button onclick="myOpen()">Open Window</button> <button onclick="myMoveTo()">MoveTo Window</button> <script> var myWindow; function myOpen(){ myWindow = window.open("", "myWindow", "width=400, height=200"); } function myMoveTo(){ myWindow.moveTo(300, 200); myWindow.focus(); } </script> </body> </html>

Syntax

window.moveTo(x, y)

Parameter Values

ValueTypeExplanation
xRequiredSpecifies the horizontal coordinate to be moved to.
yRequiredSpecifies the vertical coordinate to be moved to.

moveBy() vs moveTo()

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <button onclick="myOpen()">Open the Window</button> <button onclick="myMoveTo()">MoveTo the Window</button> <button onclick="myMoveBy()">MoveBy the Window</button> <script> var myWindow; function myOpen(){ myWindow = window.open("", "myWindow", "width=400, height=200"); } function myMoveTo(){ myWindow.moveTo(200, 100); myWindow.focus(); } function myMoveBy(){ myWindow.moveBy(40, 40); myWindow.focus(); } </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author