load jquery after the page is fully loaded

前端 未结 11 1503
甜味超标
甜味超标 2020-12-31 08:32

I\'m looking for a way to load jquery after the page is fully loaded.
well there are lots of questions and answers about it in here, but all describe how to run a scri

11条回答
  •  盖世英雄少女心
    2020-12-31 08:59

    You can try using your function and using a timeout waiting until the jQuery object is loaded

    Code:

    document.onload=function(){
        var fileref=document.createElement('script');
        fileref.setAttribute("type","text/javascript");
        fileref.setAttribute("src", 'http://code.jquery.com/jquery-1.7.2.min.js');
        document.getElementsByTagName("head")[0].appendChild(fileref);
        waitForjQuery();
    }
    
    function waitForjQuery() {
        if (typeof jQuery != 'undefined') {
            // do some stuff
        } else {
            window.setTimeout(function () { waitForjQuery(); }, 100);
        }
    }
    

提交回复
热议问题