Loading scripts dynamically

后端 未结 5 1620
青春惊慌失措
青春惊慌失措 2020-12-09 23:35

I\'m loading a few YUI scripts dynamically in my code in response to an Ajax request. The DOM and the page is fully loaded when the request is made - it\'s a response for an

5条回答
  •  一向
    一向 (楼主)
    2020-12-09 23:58

    Have you tried an onload event?

    Edited:(thanks Jamie)

    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = src;
    //IE:
    if(window.attachEvent && document.all) {
        script.onreadystatechange = function () {
            if(this.readyState === "complete") {
                callback_function(); //execute
            }
        };
    }
    //other browsers:
    else {
        script.onload = callback_function; //execute
    }
    document.getElementsByTagName("head")[0].appendChild(script);
    

提交回复
热议问题