Skip to main content

Window moveTo() Method in JAVA SCRIPT

Definition and Usage..
The moveTo() method moves a window's left and top edge to the specified coordinates.
Note: Specifying moveTo(0, 0) in Opera, results in moving the window to the top left corner of the browser, not the screen.
Return Value:No return value
Syntax : window.moveTo(x, y)
Differents way how to declare moveTo() Method in program.
CODING:
<!DOCTYPE html>
<html>
<body>
<p>Open "NewWindow" and move the new window to the top left corner of the screen:</p>
<button onclick="openWin()">Open</button>
<script>
function openWin() {
    newWindow=window.open("", "newWindow", "width=200, height=100");
    newWindow.moveTo(500, 100);
}
</script>
<br><br><br>
<button onclick="openW()">Create new window</button>
<button onclick="moveTo()">Move new window</button>
<script>
var newWindow;
function openW() {
    newWindow = window.open("", "", "width=250, height=250");
    newWindow.document.write("<p>This is newWindow click move button and move the newWindow one time:</p>");
}
function moveTo() {
    newWindow.moveTo(150, 150);
    newWindow.focus();
}
</script>
</body>
</html>

Comments