Window moveTo() Method - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window moveTo

Description

The moveTo() method moves a window's left and top edge to the specified coordinates.

Parameter Values

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

Return Value:

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:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials