Hack for IE firing multiple onResize events
Submitted by dmednikov on Tue, 2007-03-20 14:01.
AJAX & Javascript
I had in "body" tag code for onresize"myResizeFunction()". In Firefox the event fires once per window resize, IE on the other hand fires the event multiple times. And since in myResizeFunction the page was modifying the body of the page I was running into some lengthy repetetive, and sometimes infinite loops. To avoid it code needed to react only to one onResize event firing.
var resizeIE; // declare at the top of the page
and then in order to respond only to one event:
if ( document.addEventListener ){ // for Firefox
window.addEventListener("resize" , myResizeFunction, false)
} else if (document.attachEvent){ // IE hack
window.attachEvent("onresize" , function () {
window.clearTimeout(resizeIE);
resizeIE= window.setTimeout("lastResize()", 200);
}
function lastResize() {
myResizeFunction();
window.setTimeout("window.clearTimeout(resizeIE)", 100);
}
Seemed to work fine for my needs.