English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Window moveBy() method

JavaScript Window Object

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

This method moves the window relative to its current position. Conversely,window.moveTo()Move the window to an absolute position.

Syntax:

window.moveBy(x, y)
// Function to open a new window
function windowOpen() {
  popupWindow = window.open("", "", "width=200, height=200");
}
//Function to move an open window
function windowMove() {
  popupWindow.moveBy(200, 200);
  popupWindow.focus();
}
Test and See‹/›

Browser Compatibility

The moveBy() method is fully supported by all browsers:

Method
moveBy()YesYesYesYesYes

Parameter Value

ParameterDescription
xNumber of pixels to move the window horizontally. Positive values are on the right, and negative values are on the left
yNumber of pixels to move the window vertically. Positive values move down, and negative values move up

Technical Details

Return Value:None

More Examples

This example combines moveBy() with moveTo():

function windowMoveTo() {
  popupWindow.moveTo(150, 150);
  popupWindow.focus();
}
function windowMoveBy() {
  popupWindow.moveBy(100, 100);
  popupWindow.focus();
}
Test and See‹/›

Related References

Window (Window) Reference:moveTo() method

Window (Window) Reference:resizeBy() method

Window (Window) Reference:resizeTo() method

JavaScript Window Object