Javascript Reference - Window moveBy() Method








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

Browser Support

moveBy Yes Yes Yes Yes Yes

Syntax

window.moveBy(x, y)

Parameter Values

Parameter Description
x Required. number of pixels in horziontal
y Required. number of pixels in vertical




Return Value

No return value.

Example

The following code shows how to use moveBy() together with moveTo().


<!DOCTYPE html>
<html>
<body>
<!--from  w  w  w  . j  a v a  2  s  .  c  o  m-->
<button onclick="openWin()">Create new window</button>
<button onclick="moveWinTo()">Move new window</button>
<button onclick="moveWinBy()">Move the new window by 75 * 50px</button>
<script>
var myWindow;

function openWin() {
    myWindow = window.open("", "", "width=250, height=250");
}

function moveWinTo() {
    myWindow.moveTo(150, 150);
    myWindow.focus();
}

function moveWinBy() {
    myWindow.moveBy(75, 50);
    myWindow.focus();
}
</script>

</body>
</html>

The code above is rendered as follows: