1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
/** * スクリプトをロードして実行 * この方法であれば実行される */ loadingScript = (path: string) => { const targetId = "loading-script"; const loadingScriptId = document.getElementById(targetId); if (loadingScriptId) { if (loadingScriptId.getAttribute("src") === path) { // already loaded return; } loadingScriptId.remove(); // remove script tag // ReactDOM.render(<span></span>, document.getElementById("root")); // clear content } const script = document.createElement("script"); // script.src = "./path/example.js"; script.src = path; script.id = targetId; const footer = document.getElementsByTagName("footer"); footer[0].appendChild(script); } |