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.
Create 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.
Move Window
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.
Close Window
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 Include a Backslash Character in a String • Java Script Arithmetic Operators • The Document Object Model (DOM) • Window Object Properties and Methods • Java Script Trigonometric Methods • Java Script Strings • Accessing Web Page Elements • Interactively Set Webpage Colors • Java Script Trigonometric Methods • Compare Two Strings
|