Bug Tracker

Modify

Ticket #5198 (closed bug: fixed)

Opened 4 years ago

Last modified 14 months ago

ready functions being triggered (accidentally?) on 'Back' button

Reported by: candlerb Owned by: brandon
Priority: minor Milestone: 1.4
Component: event Version: 1.3.2
Keywords: ready event onload unload AJAX back Cc:
Blocking: Blocked by:

Description

I get the following behaviour on both Firefox 3.0.13 and Opera 9.63 under Ubuntu Hardy.

When you hit the 'back' button on your browser, any jQuery.ready and document.onload functions are retriggered. This could cause, for example, page components to be refetched via AJAX.

The cause of the problem seems to be this bit of jQuery:

// Prevent memory leaks in IE
// And prevent errors on refresh with events like mouseover in other browsers
// Window isn't included so as not to unbind existing unload events
jQuery( window ).bind( 'unload', function(){ 
	for ( var id in jQuery.cache )
		// Skip the window
		if ( id != 1 && jQuery.cache[ id ].handle )
			jQuery.event.remove( jQuery.cache[ id ].handle.elem );
}); 

That is - if you comment this out, behaviour reverts to expected. Pressing 'back' just shows the page how it was, and doesn't trigger the window.onload function.

However I don't know why binding an 'unload' handler would cause the behaviour of the 'back' button to change in this way.

Fixing this would (I believe) improve the client experience: the browser 'back' button would work more rapidly, and in some apps there would be less server load caused by unnecessary AJAX calls to fetch page fragments.

OTOH, it's possible that some people are actually relying on this behaviour. If so I think it should be made explicit, as it seems to be something of an accidental side-effect at present.

I'll attach a couple of pages which demonstrate the problem. Note that I'm not actually calling any jQuery functions in page1.html - just loading the jQuery framework itself.

Attachments

page1.html Download (276 bytes) - added by candlerb 4 years ago.
page2.html Download (149 bytes) - added by candlerb 4 years ago.
page1-nojq.html Download (282 bytes) - added by candlerb 4 years ago.
shows the expected behaviour (without jQuery)

Change History

Changed 4 years ago by candlerb

Changed 4 years ago by candlerb

Changed 4 years ago by candlerb

shows the expected behaviour (without jQuery)

comment:1 Changed 4 years ago by brandon

  • Owner set to brandon
  • Type changed from enhancement to bug
  • Component changed from unfilled to event

comment:2 Changed 4 years ago by brandon

Fixed in #6551

comment:3 Changed 4 years ago by brandon

  • Status changed from new to closed
  • Resolution set to fixed

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.