How to have a script in the <head> add script at the end of the <body>

后端 未结 5 1461
深忆病人
深忆病人 2020-12-07 00:51

A client is using Sharetribe which allows you add custom JS via admin, but only in the head. I want my script to load after jQuery, but jQuery is loaded at the end of the bo

5条回答
  •  無奈伤痛
    2020-12-07 01:16

    Tell your code to wait for the DOM to finish loading:

    window.onload = function() {        
        var script   = document.createElement("script");
        script.type  = "text/javascript";
        //....
    }
    

    Or using jQuery:

    $(document).ready(function() {
        var script   = document.createElement("script");
        script.type  = "text/javascript";
        //....
    });
    

提交回复
热议问题