js loader for dynamic files


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. (function(){
  2.  
  3. var myBkl = {
  4. jq: null,
  5. loadScript: function(src) {
  6. if(window.jQuery && window.jQuery.fn.jquery == '1.3.2'){
  7. return;
  8. }
  9. var s = document.createElement('script');
  10. s.setAttribute('src', src);
  11. s.setAttribute('type', 'text/javascript');
  12. document.getElementsByTagName('head')[0].appendChild(s);
  13. },
  14. whenLoaded: function(callback){
  15. if (typeof(window.jQuery) !== 'undefined' && window.jQuery.fn.jquery == '1.3.2') {
  16. myBkl.jq = window.jQuery.noConflict(true);
  17. callback(myBkl.jq);
  18. }
  19. else {
  20. setTimeout((function() {myBkl.whenLoaded(callback); }),
  21. 100);
  22. }
  23. },
  24. init: function($){
  25. console.log($.fn.jquery);
  26. console.log(window.jQuery.fn.jquery);
  27. }
  28. };
  29. myBkl.loadScript('http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js');
  30. myBkl.whenLoaded(myBkl.init);
  31. })();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.