document.write异步(JavaScript)

document.write异步(JavaScript),javascript,Javascript,我有一些跟踪代码,我必须嵌入在我的页面页脚。跟踪代码来自第三方公司,使用文档。编写当然是阻止。我已经向该公司发送了一份支持请求,他们似乎对更改代码没有任何兴趣 跟踪代码如下所示: document.write ( '<img src="http://company-url.com/visitor.gif?ts='+ new Date().getTime()+ '&ref='+escape(document.referrer) + '">' ); document

我有一些跟踪代码,我必须嵌入在我的页面页脚。跟踪代码来自第三方公司,使用
文档。编写
当然是阻止。我已经向该公司发送了一份支持请求,他们似乎对更改代码没有任何兴趣

跟踪代码如下所示:

document.write (
  '<img src="http://company-url.com/visitor.gif?ts='+
  new Date().getTime()+
  '&ref='+escape(document.referrer) + '">'
);
document.write(
''
);

所以,我的问题是,是否可以使
文档。写入
非阻塞?

不,不可能使
文档。写入
异步。但您可以在页面加载后将img附加到正文:

window.onload = function() {
    var url = 'http://company-url.com/visitor.gif?ts='+new Date().getTime()+'&ref='+escape(document.referrer);
    var img = document.createElement('img');
    img.src = url;
    document.body.appendChild(img);
};

你说它阻塞是什么意思?你能不能把它改写成
document.getElementById('footer').innerHTML='
?我不会使用
document.write
,如果我有选择的话!所以你知道,阻塞的不是
document.write
,而是所有的脚本执行都是阻塞的,除非你使用
defer
async
之类的东西。但是
document.write
不再工作了。这个第三方代码是内联脚本还是带有外部
src
?如果是后者,你就无能为力,但是如果它是内联的,你可以修改它,@bfavaretto的解决方案就行了。