The Wayback Machine - https://web.archive.org/web/20231217061734/https://www.geeksforgeeks.org/html-dom-window-moveto-method/
Open In App
Related Articles

HTML DOM Window moveTo() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The moveTo() method is used in the window to moves the window from the left and top coordinates.

Syntax: 

window.moveTo(x, y)

Parameter:  

  • x: A positive or negative number that specifies the horizontal coordinate to be moved to
  • y: A positive or negative number specifies the vertical coordinate to be moved to

Example: Move the window.  

html




<!DOCTYPE html>
<html>
<head>
    <title>
      Window moveTo() Method
    </title>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <center>
        <h1>Geeks for Geeks</h1>
        <button onclick="openWin()">
          Create
      </button>
        <button onclick="moveWin()">
          Move
      </button>
  
        <script>
            var myWindow;
  
            function openWin() {
                myWindow = 
                  window.open("",
                              "myWindow",
                              "width=200",
                              "height=100");
                
                myWindow.document.write(
                  "
<p>This is 'myWindow'</p>
");
            }
            function moveWin() {
                myWindow.moveTo(500, 100);
                myWindow.focus();
            }
        </script>
    </center>
</body>
</html>


Output: 

Initial: 

New window: 

Move window:  

Supported Browsers: The browser supported by Window moveTo() Method are listed below:  

  • Google Chrome 1
  • Mozilla Firefox 1
  • Internet Explorer 4
  • Opera 12.1
  • Safari 1
  • Edge 12

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 15 Jun, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials