Window moveBy()Method

Window 对象参考手册Window Object

Definition and Usage

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

Syntax

window.moveBy(x,y)


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the moveBy() method


Example

Example

Move the window 250 pixels relative to its current position:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.com)</title>
<script>
function openWin(){
    myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>This is my window</p>");
}
function moveWin(){
    myWindow.moveBy(250,250);
    myWindow.focus();
}
</script>
</head>
<body>

<input type="button" value="Open my window" onclick="openWin()" />
<br><br>
<input type="button" value="Move my window" onclick="moveWin()" />

</body>
</html>

Try it Yourself »


Window 对象参考手册Window Object Other Extensions