Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#5198 closed bug (fixed)

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

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 (3)

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

Download all attachments as: .zip

Change History (6)

Changed 10 years ago by candlerb

Attachment: page1.html added

Changed 10 years ago by candlerb

Attachment: page2.html added

Changed 10 years ago by candlerb

Attachment: page1-nojq.html added

shows the expected behaviour (without jQuery)

comment:1 Changed 10 years ago by brandon

Component: unfilledevent
Owner: set to brandon
Type: enhancementbug

comment:2 Changed 10 years ago by brandon

Fixed in #6551

comment:3 Changed 10 years ago by brandon

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.