Use moveBy Method to Move Window by a Specific Offset
By Stephen Bucaro
In this article, I show you how to use Java Script to move a window from its current position
to a new position by an offset number of pixels. To accomplish that, I will use the window
object's moveBy method. Click on the link below to create a window.
I used a variable named moveBYwin in the window.open method to create the window.
We can use that variable name to control the window. Shown below is code to move the window 20
pixels to the right and 20 pixels down.
<a href="#" onclick="moveBYwin.moveBy(20,20);">Move Window</a>
Click on the link below to move the window. It will move 20 pixels to the right and 20 pixels
down each time you click the link.
When you click on the link, it gives the focus to the window with the link, so your browser
window may hide the moveBYwin window. In that case, click on the link below to move it
to the top where you can see its new location.
Move to Top
Eventually, you may want to close the moveBYwin window. To do that click in the link below.
If you want to move a window to a specific loation on the screen, then you're looking for
the moveTo method.
More Java Script Code:
• Java Script Strings
• Java Script Math.cos Method
• Java Script Math.tan Method
• Java Script Data Types
• The do/while Loop
• The Navigator Object
• The Conditional Operator
• Search and Replace Strings