Open In App

HTML DOM Window moveTo() Method

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

Syntax: 



window.moveTo(x, y)

Parameter:  

Example: Move the window.  






<!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:  


Article Tags :