load the external JavaScript dynamically

script 2013. 9. 25. 10:03



[출처] http://www.hbirddesigns.com/~launch/articles/a-simple-explanation-on-loading-external-javascript-dynamically-into-a-web-page/


외부 javascript 를 동적으로 생성해서 필요 시에만 로드 하자!!

//Create a 'script' element
var scrptE = document.createElement("script");

// Set it's 'type' attribute
scrptE.setAttribute("type", "text/javascript");

// Set it's 'language' attribute
scrptE.setAttribute("language", "JavaScript");

// Set it's 'src' attribute
scrptE.setAttribute("src", "myjsfile.js");

// Now add this new element to the head tag
document.getElementsByTagName("head")[0].appendChild(scrptE);



Trackbacks 0 : Comments 0

Write a comment