Loading scripts after page load?

后端 未结 7 1652
粉色の甜心
粉色の甜心 2020-11-27 15:16

I work with an advertising company, where we tag certain pages to track activity. A client of mine wants to fire off a javascript tag to track activity AFTER the page has fi

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 15:44

    Here is a code I am using and which is working for me.

    window.onload = function(){
        setTimeout(function(){
            var scriptElement=document.createElement('script');
            scriptElement.type = 'text/javascript';
            scriptElement.src = "vendor/js/jquery.min.js";
            document.head.appendChild(scriptElement);
    
            setTimeout(function() {
                var scriptElement1=document.createElement('script');
                scriptElement1.type = 'text/javascript';
                scriptElement1.src = "gallery/js/lc_lightbox.lite.min.js";
                document.head.appendChild(scriptElement1);
            }, 100);
            setTimeout(function() {
                $(document).ready(function(e){
                    lc_lightbox('.elem', {
                        wrap_class: 'lcl_fade_oc',
                        gallery : true, 
                        thumb_attr: 'data-lcl-thumb', 
                        slideshow_time  : 3000,
                        skin: 'minimal',
                        radius: 0,
                        padding : 0,
                        border_w: 0,
                    }); 
                });
            }, 200);
    
        }, 150);
    };
    

提交回复
热议问题