Window moveTo()Method

Window 对象参考手册Window Object

Definition and Usage

The moveTo() method moves the upper-left corner of a window to a specified coordinate.

Syntax

window.moveTo(x,y)


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the moveTo() method

Note:Specify moveTo(0.0) to place the window at the upper-left corner of the browser in Opera.


Example

Example

Move the new window to the upper-left corner of the screen:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example(example.com)</title>
<script>
function openWin(){
    myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>This is my window</p>");
}
function moveWin(){
    myWindow.moveTo(0,0);
    myWindow.focus();
}
</script>
</head>
<body>

<input type="button" value="Open Window" onclick="openWin()" />
<br><br>
<input type="button" value="Move Window" onclick="moveWin()" />

</body>
</html>

Try it Yourself »


Window 对象参考手册Window Object Other Extensions