Skip to content

Instantly share code, notes, and snippets.

@tmilewski
Created March 31, 2011 15:23
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tmilewski/896561 to your computer and use it in GitHub Desktop.
Save tmilewski/896561 to your computer and use it in GitHub Desktop.
Replace the normal jQuery getScript function with one that supports debugging and which references the script files as external resources rather than inline. Helps with debugging in IE.
// Helps with IE debugging.
jQuery.extend({
getScript: function(url, callback) {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
var done = false; // Handle Script loading
script.src = url;
script.onload = script.onreadystatechange = function() { // Attach handlers for all browsers
if ( !done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") ) {
done = true;
if (callback) { callback(); }
script.onload = script.onreadystatechange = null; // Handle memory leak in IE
}
};
head.appendChild(script);
return undefined; // We handle everything using the script element injection
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment