HTML and CSS Reference
In-Depth Information
Moving and Resizing a Window. JavaScript provides several methods with which
to resize and move a window object. The window can be moved or resized absolutely, or
relative to its current position or size. The numbers, given as arguments, are the pixel
coordinates, and are listed in Table 10.7.
Table 10.7 Move and Resize Methods
Method
Example
What It Does
moveBy()
moveBy(20,20)
Moves the window relatively by 20 pixels.
moveTo()
moveTo(0,0)
Moves to the top, left corner of the screen.
resizeBy()
resizeBy(15,10)
Resizes the window relatively by 15 × 10 pixels.
resizeTo()
resizeTo(450,350)
Resizes the window absolutely to 450 × 350
pixels.
EXAMPLE 10.9
<html>
<head><title>Move a New Window</title>
<script type="text/javascript">
function directions(){
1
winObj=window.open("myplace.html","myplace",
"width=200,height=300, resizable=no");
2
winObj.moveTo(0, 0); // Move window to top left corner
3
winObj.focus();
4
parent.window.moveTo(215, 0); // Move the parent window
5
parent.window.resizeTo(400,400); // Resize browser window
}
function closeWindow(){
winObj.close();
}
</script>
</head>
<body bgColor="lightblue">
<h2>We've moved!</h2>
For directions to our new place,
<br />
click the button
6
<form >
<input type="button"
value="Simple Directions"
7
onClick="directions();">
<p>When you are ready to close the window, click here</p>
</form>
<a href="JavaScript:closeWindow()">Close the window</a>
</body>
</html>
 
Search WWH ::




Custom Search