Moving WindowsYou can use the moveBy and moveTo methods to move windows. The moveBy method moves a window by a given (positive or negative) X and Y offset, and the moveTo method moves a window to a specific X and Y location. Both methods take two argumentsthe X and Y offset (for moveBy ) or new position (for moveTo ), measured in pixels. X and Y coordinates for the moveBy and moveTo methods are measured in screen coordinates, where (0, 0) is the upper-left corner of the screen; positive X is to the right, and positive Y is downward. To move 10 pixels down and 5 pixels to the left, for example, use moveBy(-5, 10) . Note that this is true for all JavaScript graphical methods: (0, 0) is at upper left (the upper left of the screen for the moveBy and moveTo methods, but possibly the upper left of other windowssuch as the browser windowfor certain other methods), positive X is to the right, and positive Y is downward. Here's an example that moves the browser to the upper-left corner of the screen: (Listing 08-04.html on the web site)<HTML> <HEAD> <TITLE>Using the moveTo method</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function mover() { window.moveTo(0, 0) } // --> </SCRIPT> </HEAD> <BODY> <H1>Using the moveTo method</H1> <FORM> <INPUT TYPE="BUTTON" ONCLICK="mover()" VALUE="Click Me!"> </FORM> </BODY> </HTML> |