The moveBy() method

The moveBy() method can be used to move a window on the scree from one location to another.


A negative number will move the window to the left and to the top, and a positive number will move the window to the right and to the bottom.

Let’s modify the newpage.html again and add a button that can move the window by a number of pixels of your choice.

<h1>I am an amazing new window<br>
I have been opened with JavaScript.</h1>
<input type="button" value="Move Window" onclick="window.moveBy(50,50);" />
<input type="button" value="Close Window" onclick="window.close();" />

Since the button is still on the page, you can move the window again and again. It will work as long as it is pressed.

Leave a Reply