Bug Tracker

Modify

Ticket #1625 (closed bug: wontfix)

Opened 6 years ago

Last modified 14 months ago

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:
Blocking: Blocked by:

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

comment:1 Changed 6 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.

comment:2 Changed 6 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/

comment:3 Changed 5 years ago by harking

  • Status changed from closed to reopened
  • Resolution wontfix 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.

comment:20 Changed 3 years ago by dmethvin

  • Status changed from reopened to closed
  • Resolution set to wontfix

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 follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.