Resizing a Window


window.resizeTo(640, 480); 

There are several ways to set a window's size. When opening a window using window.open(), you just have to set the width and height options. For existing windows, however, JavaScript offers two methods of the window object:

  • resizeTo() sets the width and the height of the window to the provided values, as the preceding code (file resizeto.html in the download archive) shows.

  • resizeBy() changes the width and the height of the window by adding the provided values, as the following listing shows (which cuts both the width and the height in half):

    Bisecting a Window's Width and Height (resizeby.html)

    <script language="JavaScript"   type="text/javascript"> window.onload = function() {   var width, height;   if (window.innerWidth) {     width = window.outerWidth;     height = window.outerHeight;   } else {     width = document.body.clientWidth;     height = document.body.clientHeight;   }   window.resizeBy(     -Math.round(width / 2),     -Math.round(height / 2)); } </script> <body></body> 

Warning

Resizing a window is considered more or less unfriendly. One of the principles of the Web is that the size of the client is irrelevant and can be adjusted by the user. So use the technique in this phrase wisely. Also note that you cannot resize the window to a width or height lower than 100 pixels.





JavaScript Phrasebook(c) Essential Code and Commands
JavaScript Phrasebook
ISBN: 0672328801
EAN: 2147483647
Year: 2006
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net