December 28, 1999 - The onresize-reload Trap | WebReference

December 28, 1999 - The onresize-reload Trap

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

Yehuda Shiran, Ph.D.
Doc JavaScript

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.