Bug Tracker

Opened 13 years ago

Closed 13 years ago

#1130 closed enhancement (fixed)

JS error in IE and FireFox in ASP.NET 2.0 after reloading page

Reported by: halex Owned by:
Priority: major Milestone: 1.1.3
Component: event Version: 1.1.2
Keywords: Cc:
Blocked by: Blocking:

Description

I am providing solution for this Threas http://dev.jquery.com/ticket/999

In original function was only at the end:

// A fallback to window.onload, that will always work
jQuery.event.add( window, "load", jQuery.ready );

but this is not good for IE and Firefox (problem with ASP.NET 2.0 described in this article...)

Replace this function on row number 1468 with this modified by me and it will work:

new function(){

	jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
		"mousedown,mouseup,mousemove,mouseover,mouseout,change,select," + 
		"submit,keydown,keypress,keyup,error").split(","), function(i,o){
		
		// Handle event binding
		jQuery.fn[o] = function(f){
			return f ? this.bind(o, f) : this.trigger(o);
		};
			
	});
	
	// If Mozilla is used
	if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
		// Use the handy event callback
		document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
	
		// A fallback to window.onload, that will always work
		jQuery.event.add( window, "load", jQuery.ready );
	}
	// If IE is used, use the excellent hack by Matthias Miller
	// http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
	else if ( jQuery.browser.msie ) {
	
		// Only works if you document.write() it
		document.write("<scr" + "ipt id=__ie_init defer=true " + 
			"src=//:></script>");
	
		// Use the defer script hack
		var script = document.getElementById("__ie_init");
		
		// script does not exist if jQuery is loaded dynamically
		if ( script ) 
			script.onreadystatechange = function() {
				if ( this.readyState != "complete" ) return;
				this.parentNode.removeChild( this );
				jQuery.ready();
			};
	
		// Clear from memory
		script = null;
	
		// A fallback to window.onload, that will always work
		window.oldLoad = window.oldLoad; 
		window.onload = function(event) { 
		    jQuery.ready(); 
		    window.oldLoad(event); 
		    window.oldLoad = null; 
		} 
	// If Safari  is used
	} else if ( jQuery.browser.safari ) {
		// Continually check to see if the document.readyState is valid
		jQuery.safariTimer = setInterval(function(){
			// loaded and complete are both valid states
			if ( document.readyState == "loaded" || 
				document.readyState == "complete" ) {
	
				// If either one are found, remove the timer
				clearInterval( jQuery.safariTimer );
				jQuery.safariTimer = null;
	
				// and execute any waiting functions
				jQuery.ready();
			}
		}, 10); 
		
		// A fallback to window.onload, that will always work
		jQuery.event.add( window, "load", jQuery.ready );
	}
};

Best regards Aleksandar Hajduković

Change History (1)

comment:1 Changed 13 years ago by brandon

Component: ajaxevent
Resolution: fixed
Status: newclosed

In the latest SVN we have moved to using DOM 2 event handlers which will prevent these collisions from happening.

Note: See TracTickets for help on using tickets.