Javascript Browser Window moveTo() Method

Introduction

Open a new window, and move the new window to the top left corner of the screen:

View in separate window

<!DOCTYPE html>
<html>
<body>

<p>Open "myWindow" and move the new window to the top left corner of the screen:</p>

<button onclick="openWin()">Open "myWindow"</button>
<button onclick="moveWin()">Move "myWindow"</button>

<script>
var myWindow;//from   w w  w .j  ava2 s  .  c  o  m

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>

</body>
</html>

The moveTo() method moves a window's left and top edge to the specified coordinates.

Specifying moveTo(0, 0) in Opera, results in moving the window to the top left corner of the browser, not the screen.

moveTo(x, y);

Parameter Values

Parameter Type Description
x Number Required. A positive or negative number that sets the horizontal coordinate to be moved to
y Number Required. A positive or negative number sets the vertical coordinate to be moved to



PreviousNext

Related