spacer
Yehuda Shiran December 28, 1999
The onresize-reload Trap
Tips: December 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

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

In Navigator 4.0x, absolutely positioned elements get messed up when the browser window is resized. Therefore, we'll instruct the browser to reload the page if the user happens to resize the window. In theory, the code would be:

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

if (NS4) window.onresize = redo;

The preceding code segment worked fine -- until Netscape introduced Navigator 4.04. On Navigator 4.04, a resize event occurs when the page loads. Our redo() function then reloads the page, and a resize event occurs (again). This process traps our page in a loop -- the page reloads continuously. We solved the problem by setting the window.onresize event handler one second after the page loads:

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

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

if (style) {
  .
  .
  .
  if (NS4) window.onload = init;
}

Learn more about how we used this code in Column 16, Dynamic Tooltips.


People who read this tip also read these tips:

Look for similar tips by subject:

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