onResize (Event handler)

As the window is resized, this event is triggered.

Availability:

JavaScript - 1.2
JScript - 3.0
Internet Explorer - 4.0
Netscape - 4.0
Property/method value type:Boolean primitive
JavaScript syntax:-myObject.onresize = aHandler
HTML syntax:<BODY onResize="aHandler"> <FRAMESET onResize="aHandler"> <HTMLTag onResize="aHandler">
Argument list:aHandlerA reference to a function object to handle the event

Moving or resizing windows may be something your scripts will need to know about. A move is generally harmless, but a resize may not be so benign to your page content. This event trigger provides a means to fix up the display if the window aspect ration or size is changed.

This event is triggered when a window is enlarged or reduced in size.

The handler is registered by defining it with an HTML tag attribute. The handler can also be registered by assigning the function object to the onresize property of the window.

The event is also triggered when a window is resized under control of a script with the resizeTo() or moveBy() methods.

Warnings:

Example code:

   // This checks to see if the window's dimensions have

   // actually changed (because Netscape often fires a

   // false onResize event when it forms scrollbars);

   // if the dimensions have changed, the document is

   // reloaded.

   // Note that document.location is not supposed to be

   // settable, but here's another case where the

   // implementation does not match the specs.

   function resizeFix()

   {

      if((document.resizeFix.initWidth  != window.innerWidth) ||

         (document.resizeFix.initHeight != window.innerHeight))

      {

         document.location = document.location;

      }

   }

   // This function checks to see if the browser supports the

   // Layer object (i.e., Netscape 4.X);

   // If it does, then it creates a new object with properties

   // to hold the current window width & height and assigns

   // the resizeFix() function to the window's onResize event.

   function checkBrowser()

   {

      if(document.layers)

      {

         if(typeof document.fix == "undefined")

         {

            document.resizeFix = new Object();

            document.resizeFix.initWidth  = window.innerWidth;

            document.resizeFix.initHeight = window.innerHeight;

         }

         window.onresize = resizeFix;

      }

   }

   // This calls the browser check function above

   checkBrowser();

See also:Event, Event handler, Event model, Event names, Event object, Event.returnValue, Handler, Semantic event, Window events, Window.onresize

Supported by objects:

APPLET

AREA

BUTTON

DIV

FIELDSET

FRAMESET

IMG

Input

MARQUEE

Select

TABLE

TD

Window