Window moveTo() method

Definition and usage

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

See also:

moveBy() method

resizeBy() method

resizeTo() method

Example

Example 1

Open a new window and move it to position 500 x 100:

function openWin() {
  myWindow = window.open('', '', 'width=400, height=200');
}
function moveWin() {
  myWindow.moveTo(500, 100);
}

Try it yourself

Example 2

Using moveTo() together with moveBy():

Using moveTo() together with moveBy():
function moveWinTo() {
  myWindow.moveTo(150, 150);
}
function moveWinBy() {
  myWindow.moveBy(75, 50);
}

Try it yourself

Syntax

window.moveTo(x, y)

Parameter

Parameter Description
x Required. A positive or negative number. The horizontal coordinate to move to.
y Required. A positive or negative number. The vertical coordinate to move to.

Return value

None.

Description

moveTo() methods will move the window window, so that its upper left corner is at x and y specified location.

For security reasons, browsers limit methods so that they cannot move windows out of the screen.

It is usually a bad idea to move a browser window for mobile users, unless the user explicitly requests it. Scripts should only be moved by themselves through window.open() Use this method on the window created.

Browser Support

All Browsers Support moveTo():

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support