简体   繁体   English

如何延迟 3rd 方统计 javascripts

[英]How to delay 3rd party stats javascripts

i want to delay 3rd party stats java scripts..like revolver maps,feedjit,whos.amung.us (stats scripts ) how to?我想延迟第 3 方统计 java 脚本......比如左轮手枪地图、feedjit、whos.amung.us(统计脚本)如何? if i use "defer".it defers for lifetime.how do i delay them thankx in advance!如果我使用“延迟”。它会延迟终生。我如何提前延迟它们谢谢!

Use setTimeOut(function,1000);使用setTimeOut(function,1000); to delay the execution of a function by 1000ms (1s)将 function 的执行延迟 1000 毫秒(1 秒)

I guess you're talking about libraries that are loaded by just including a script element?我猜您是在谈论仅通过包含script元素来加载的库? I guess something like this should work:我想这样的事情应该有效:

setTimeout(function() {
  var headElement = document.getElementsByTagName("head")[0];         
  var scriptElement = document.createElement('script');
  scriptElement.type = 'text/javascript';
  scriptElement.src = 'http://my.library.url/my.library.js';
  headElement.appendChild(scriptElement);
}, 3000);

This should schedule your library to be injected 3 seconds later.这应该安排您的库在 3 秒后注入。

If you need to also run some code when it's loaded, include this somewhere in the middle:如果您还需要在加载时运行一些代码,请将其包含在中间的某个位置:

  scriptElement.onload = function() {
    myLibraryInitFunction(myLibraryInitParameters);
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM