Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evidens/2573087 to your computer and use it in GitHub Desktop.
Save evidens/2573087 to your computer and use it in GitHub Desktop.
Conditionally Load jQuery
//Conditionally load jQuery
//inspired by http://www.smashingmagazine.com/2010/05/23/make-your-own-bookmarklets-with-jquery/
window.onload = function () {
if (typeof jQuery == 'undefined') {
var jQ = document.createElement('script');
jQ.type = 'text/javascript';
jQ.onload = jQ.onreadystatechange = myOnLoadEvent;
jQ.src = ( "https:" == location.protocol ? "https://" : "http://" ) + 'ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
document.body.appendChild(jQ);
} else {
myOnLoadEvent();
}
};
function myOnLoadEvent() {
jQuery(document).ready(function($) {
alert('your code here');
});
}
@evidens
Copy link
Author

evidens commented May 2, 2012

Add : to protocols to fix error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment