JS Window moveBy()

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

Syntax

window.moveBy(x, y)

Parameters

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.

Return Value

NONE

JS Window moveTo()

The moveTo() method moves a window to the specified coordinates.

Syntax

window.moveTo(x, y)

Parameters

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.

Return Value

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>