#1625 closed bug (wontfix)
resize event handler is called twice in IE
Reported by: | aercolino | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.2.1 |
Component: | event | Version: | 1.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
In IE7 (at least) the resize event handler is called twice. For example, in the following script I get 6 alerts instead of 3. The commented code is a workaround.
jQuery( window ) .bind( 'resize', /*{ count: 1 },*/ function( event ){ /* if (event.data.count == 1) { event.data.count = 0; } else { event.data.count = 1; return; } */ var w = $( window ); var d = $( document ); var b = $( 'body' ); alert( 'w: ' + w.width() + ', ' + w.height() ); alert( 'd: ' + d.width() + ', ' + d.height() ); alert( 'b: ' + b.width() + ', ' + b.height() ); } );
I thought that the 'one' method could fit here but maybe I misunderstood its intended usage. In fact, it works once, and then never more. For the first resizing, the handler bound with 'one' is called, but for any other resizing after the first one, the handler is never called again. (unbound?)
Change History (4)
comment:1 Changed 15 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 Changed 15 years ago by
OK. I've put up a jQuery plugin for solving this issue: http://noteslog.com/post/how-to-fix-the-resize-event-in-ie/
comment:3 Changed 15 years ago by
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
Can this issue be looked into again? It seems that a fix for this would fit perfectly into jQuery core, rather than a plugin.
comment:20 Changed 13 years ago by
Resolution: | → wontfix |
---|---|
Status: | reopened → closed |
This really seems tricky to work around in jQuery, but relatively easy for an application to solve using one of the approaches above. If there's a simple patch someone can contribute for the problem, feel free to attach it and reopen the ticket.
Please see this article for a possible workaround for this IE issue: http://snook.ca/archives/javascript/ie6_fires_onresize/
You could also use a setTimeout to call another function ... if the resize method is called again before the setTimeout has fired, just reset it.
And you are correct about the one method. It unbinds the event after it fires the first time.