etc

Jquery Load 유무 체크하기

by kay posted Feb 12, 2014
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

페이지 내에 Jquery 가 정상적으로 load 되었는지 체크 하는 방법입니다.


// 1.
if (window.jQuery) {  
    // jQuery is loaded  
} else {
    // jQuery is not loaded
}

// 2.
if (typeof jQuery == 'undefined') {  
    // jQuery is not loaded
} else {
    // jQuery is loaded
}

// .. 만약 Load 되어있지 않다면.. 추가하기
if (!window.jQuery) {
  var jq = document.createElement('script'); jq.type = 'text/javascript';
  jq.src = 'http://code.jquery.com/jquery-latest.min.js';
  document.getElementsByTagName('head')[0].appendChild(jq);
}


참고 Url : http://jquery-howto.blogspot.kr/2009/03/check-if-jqueryjs-is-loaded.html