Site Navigation

Monday, October 29, 2007

bug 104 - resize event firing errors in IE on Maximize or Restore

Issue: #104
Affects: IE5, IE5.5, IE6, IE7, IE8 Beta 1, IE8 Beta 2, IE8 PR1, IE8 RC1
Partially Fixed in: IE7 & IE8* (see details below)
Fixed in: IE9 RC 1 (in IE9 standards mode only)

The resize event when applied to the window, will fire when the browser is resized.

In IE, it fires continually while stretching a window, and in other browsers only when the dragging stops and a new window size is set. (this isn't the bug, just a minor difference in the way each browser works)

The bug, is that IE will fire multiple resize events for a single resize of the browser, when Maximizing or Restoring the window.

In IE6, a Maximize or Restore window setting will trigger 3 (three!) resize events.

You can do this by right-clicking the task bar and choosing from the context menu, or by double-clicking the title bar of the browser.

In IE7, they fixed this! Well, not quite. In IE7, it now fires 2 (two!) resize events. Well, I suppose that 1 invalid resize event, is better than 2 invalid resize events, but suffice to say, there is still a significant bug here. This incorrect behavior is still seen in IE8 builds up until IE8 RC1.


Example:

<script>
window.onresize = function(){
alert('resizing: Offset: ' +
document.body.offsetWidth + ', ' +
document.body.offsetHeight +
'\nScroll: ' +
document.body.scrollWidth + ', ' +
document.body.scrollHeight);
};
</script>



Known Workarounds: None. If you need to ensure that a function is called only once for this kind of resize, you may want to store the current width and height dimensions as variables, then onresize, compare them against the stored size. If they are both a match, ignore the event. (e.g. there was no resize)


Related Issues: None.