-
-
Save ctbarna/918065 to your computer and use it in GitHub Desktop.
Conditionally load jQuery (with slight version independence). Not expecting the API to change a whole lot in the sub-versions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js'; | |
document.body.appendChild(jQ); | |
} else { | |
myOnLoadEvent(); | |
} | |
}; | |
function myOnLoadEvent() { | |
jQuery(document).ready(function($) { | |
alert('your code here'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jQ.onload was not referencing a real function.