Window moveBy() Method - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window moveBy

Description

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

Parameter Values

Parameter Type Description
x Number Required. A positive or negative number to move the window horizontally
y Number Required. A positive or negative number to move the window vertically

Return Value:

No return value

The following code shows how to Open a new window, and move the new window 250px relative to its current position:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
var myWindow;//from   ww w.j a  v a  2 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.moveBy(250, 250);
    myWindow.focus();
}
</script>

</body>
</html>

Related Tutorials