domingo, 3 de julio de 2011

¡Qué gracia tiene!

¡Qué arte! ¡Qué duende! ¡Qué tronío tiene Internet Explorer! Pero no sólo el 6, ¡todos! Y yo sin enterarme... de nuevo me caigo del guindo.

Resulta que si capturas el evento resize del objeto window del navegador, todo va bien mientras no se te ocurra recolocar y/o cambiar de tamaño cualquier elemento de la página. Es entonces cuando Internet Explorer decide que lo vuelve a lanzar y lanzar y relanzar... y termina su gran actuación con el mítico chiste Out of memory.

El bug está documentado por todas partes para IE6 e IE7 pero yo también lo he visto en plena acción en IE8. De las soluciones que he encontrado, las dos más utilizadas son: utilizar un timeout que rompa la cadena de recoloco-capturo_evento-recoloco-capturo_evento y eliminar el manejador del evento en el momento que se empiezan a recolocar elementos y reponerlo al terminar.

Yo he optado por una mezcla. Con JQuery...

function manageResize(){
 $(window).unbind('resize');

 ...haz lo que tengas que hacer...

 setTimeout('$(window).resize(function(e){manageResize();})', 25);
}

Es decir, elimino el manejador y, al terminar, lo recupero con un timeout de unos pocos milisegundos para darle tiempo a que los eventos que genera la recolocación de elementos se pierdan en el infierno de los bytes.

Y nada más. ¡Salud y rocanrol!

All aboard!

Crazy, but that's how it goes
Millions of people living as foes
Maybe it's not too late
To learn how to love
And forget how to hate

Mental wounds not healing
Life's a bitter shame
I'm going off the rails on a crazy train!

I've listened to preachers
I've listened to fools
I've watched all the dropouts
Who make their own rules
One person conditioned to rule and control
The media sells it and you live the role

Mental wounds still screaming
Driving me insane
I'm going off the rails on a crazy train!

I know that things are going wrong for me
You gotta listen to my words
Yeah!

Heirs of a cold war
That's what we've become
Inheriting troubles I'm mentally numb
Crazy, I just can not bare
I'm living with something
that just isn't fair

Mental wounds not healing
Who and what's to blame
I'm going off the rails on a crazy train!

No hay comentarios: