moveBy()
method moves a window a number of pixels
relative to its current coordinates.
window.moveBy(x, y)
Parameter | Description |
x |
Required. A positive or negative number. The number of pixels to move the window horizontally. |
y |
Required. A positive or negative number. The number of pixels to move the window vertically. |
NONE |
The moveTo()
method moves a window to the specified
coordinates.
window.moveTo(x, y)
Parameter | Description |
x |
Required. A positive or negative number. The horizontal coordinate to move to. |
y |
Required. A positive or negative number. The vertical coordinate to move to. |
NONE |
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<button onclick="openWindow()">Open Window</button>
<button onclick="moveWindow()">Move Window</button>
<script>
/* JavaScript MoveBy And MoveTo Window Method */
var myWindow;
function openWindow(){
myWindow = window.open("","","width=500px,height=200px,left=100px,top=100px");
myWindow.document.write("<p>This is my Window.</p>")
}
/*function moveWindow(){
myWindow.moveTo(200,200);
myWindow.focus();
}*/
function moveWindow(){
myWindow.moveBy(200,200);
myWindow.focus();
}
</script>
</body>
</html>