How to run/load a separate javascript file selectively from inside javascript?

前端 未结 4 399
生来不讨喜
生来不讨喜 2021-01-24 16:01

I have 3 JavaScript files that I would like to load from an index.html file. I\'m choosing among them by using if statements which I only know how to d

4条回答
  •  无人及你
    2021-01-24 16:32

    By appending the script to the document.

    if(window.innerHeight == 800){
        var script = document.createElement("script");
        script.src = "storybook.js";
        document.getElementsByTagName("head")[0].appendChild(script);
    }
    

提交回复
热议问题