spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column19


Resizing the Page

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

In Navigator 4.0x, a dynamic content layout is lost when the user resizes the browser window. In order to restore the layout of the page, we must reload the page when a resize event occurs:

if (NS4) onresize = redo;

function redo() {
  location.reload();
}

We set the onresize event handler to redo, so the redo() function is invoked when the window is resized. It, in turn, reloads the page by calling the built-in location.reload() method.

In Navigator 4.0x, a resize event occurs when the page loads, immediately after the load event. So when the redo() function reloads the page, the onresize event handler is triggered again, causing an endless loop. As a matter of fact, the loop starts when the page is first loaded, because the "side-effect" resize event occurs when the page loads.

The workaround is just as simple. We need to set the onresize event handler after the page loads, so the "side-effect" resize event doesn't trigger it. We'll use the well-known setTimeout() function to achieve our goal:

if (NS4) onload = init;

function init() {
  setTimeout("onresize = redo", 1000);
}

function redo() {
  location.reload();
}

The Dynamic HTML Lab has more information on the onload/onresize bug.

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Created: May 21, 1998
Revised: May 21, 1998

URL: http://www.webreference.com/js/column19/resize.html