Javascript Browser Window moveBy() Method

Introduction

Open a new window, and move the new window 250px relative to its current position:

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="openWin()">Open "myWindow"</button>
<button onclick="moveWin()">Move "myWindow"</button>

<script>
var myWindow;/*  ww w .ja  v  a  2  s  . co m*/

function openWin() {
  myWindow = window.open("", "myWindow", "width=200, height=100");
  myWindow.document.write("<p>This is 'myWindow'</p>");
}

function moveWin() {
  myWindow.moveBy(250, 250);
  myWindow.focus();
}
</script>

</body>
</html>

The moveBy() method moves a window a specified number of pixels relative to its current coordinates.

Related methods:

  • moveTo() - Moves a window to the specified position
  • resizeBy() - Resizes the window by the specified pixels
  • resizeTo() - Resizes the window to the specified width and height
moveBy(x, y);

Parameter Values

Parameter
Type
Description
x

Number

Required.
A positive or negative number that specifies the amount of pixels to move the window horizontally
y

Number

Required.
A positive or negative number that specifies the amount of pixels to move the window vertically



PreviousNext

Related