07/19: Javascript > 動的にファイルを読み込む
Category: Web dev
Posted by: hajime osako
How to Dynamically load JavaScript Source files to a webpage
//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);