Can't append [removed] element

后端 未结 18 2266
被撕碎了的回忆
被撕碎了的回忆 2020-11-21 06:11

Any idea why the piece of code below does not add the script element to the DOM?

var code = \"\";
$(\"#someElement\").append(cod         


        
18条回答
  •  無奈伤痛
    2020-11-21 06:46

    This is what I think is the best solution. Google Analytics is injected this way.

    var (function(){
        var p="https:" == document.location.protocol ? "https://" : "http://";
            d=document,
            g=d.createElement('script'),
            s=d.getElementsByTagName('script')[0];
            g.type='text/javascript';
            g.src=p+'url-to-your-script.js';
            s.parentNode.insertBefore(g,s); })();
    

提交回复
热议问题