Javascript examples for Browser Object Model:Window moveTo
The moveTo() method moves a window's left and top edge to the specified coordinates.
Parameter | Type | Description |
---|---|---|
x | Number | Required. A positive or negative number for the horizontal coordinate |
y | Number | Required. A positive or negative number for the vertical coordinate |
No return value
The following code shows how to Open a new window, and move the new window to the top left corner of the screen:
<!DOCTYPE html> <html> <body> <button onclick="openWin()">Open "myWindow"</button> <button onclick="moveWin()">Move "myWindow"</button> <script> var myWindow;/* w w w. ja va 2s . com*/ function openWin() { myWindow=window.open("", "myWindow", "width=200, height=100"); myWindow.document.write("<p>This is 'myWindow'</p>"); } function moveWin() { myWindow.moveTo(500, 100); myWindow.focus(); } </script> </body> </html>