©ilj@flowsim.se
JavaScript code samples 68
JavaScript resizeBy(), resizeTo()

 

 

Click
here
to open
a new window
!

 
 
code & explanations below




 
Here is a function that decreases the width and the height of a window by 30 pixels:
 

function iljresize()
{
self.resizeBy(-30,-30)
}

 
Put the function between SCRIPT tags in the HEAD part (see JavaScript 1 basics).
 
A call could look like this:
 

<A HREF="
#"
ONCLICK="iljresize();return false">resize window</A>
 
Each time you click the link the window gets smaller. If you remove the minus signs the window will become bigger and bigger. You cannot make a window smaller than 100x100 pixels.
 
a square

 
If you want the window to have a specific size you can use resizeTo() e g
 

function iljresize2()
{
self.resizeTo(640,480)
}

 
This will make the window 640 pixels wide and 480 pixels high.
 
Since this is code that does not work in all browsers it might be a good idea to use browser-detecting code (more about that under JavaScript 1 basics).

 
a square
 

 
a line
Page by
 
ilj
 
ilj@flowsim.se
 
a square
 
a square
 
Last modified: August 27, 1999
 
This page should be part of a frames system
at
http://www.flowsim.se