Skip to content

Instantly share code, notes, and snippets.

@kputnam
Last active December 29, 2015 20:22
Show Gist options
  • Save kputnam/8258ef96b2a9b1a8587f to your computer and use it in GitHub Desktop.
Save kputnam/8258ef96b2a9b1a8587f to your computer and use it in GitHub Desktop.
jQuery Bookmarklet
(function() {
var otherLib = (typeof($) == 'function');
if (typeof(jQuery) != 'undefined') {
alert('jQuery already defined');
return;
}
function getScript(url, callback) {
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0],
done = false;
script.onload = script.onreadystatechange = function() {
if ( !done && (!this.readyState
|| this.readyState == 'loaded'
|| this.readyState == 'complete') ) {
done = true;
callback();
script.onload = script.onreadystatechange = null;
head.removeChild(script);
}
};
head.appendChild(script);
}
getScript('http://code.jquery.com/jquery-latest.min.js', function() {
if (typeof jQuery == 'undefined')
alert('Unable to load jQuery');
else if (otherLib)
alert('No conflict mode, use $jq()');
else
alert('jQuery is loaded');
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment