Bug Tracker

Ticket #1625 (reopened bug)

Opened 2 years ago

Last modified 9 months ago

resize event handler is called twice in IE

Reported by: aercolino Assigned to: anonymous
Type: bug Priority: major
Milestone: 1.2.1 Component: event
Version: 1.2 Keywords:
Cc: Needs: Review

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?)

Attachments

Change History

Changed 2 years ago by brandon

  • status changed from new to closed
  • resolution set to wontfix

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.

Changed 2 years ago by aercolino

OK. I've put up a jQuery plugin for solving this issue: http://noteslog.com/post/how-to-fix-the-resize-event-in-ie/

Changed 1 year ago by harking

  • status changed from closed to reopened
  • resolution deleted

Can this issue be looked into again? It seems that a fix for this would fit perfectly into jQuery core, rather than a plugin.

Note: See TracTickets for help on using tickets.