Javascript 如何在10秒后加载跟踪像素?
我的公司想从一家广告发布机构获得一些流量,他们给了我们一个像素跟踪代码,并强迫我们在10秒钟后将其加载到网站上。 我试图通过JS实现这一点,但还是失败了 以下是像素的外观:Javascript 如何在10秒后加载跟踪像素?,javascript,pixel,Javascript,Pixel,我的公司想从一家广告发布机构获得一些流量,他们给了我们一个像素跟踪代码,并强迫我们在10秒钟后将其加载到网站上。 我试图通过JS实现这一点,但还是失败了 以下是像素的外观: `<img src="https://ext.example.com/conversion/?c=122959&a=30225" width="1" height="1" onerror="this.onerror=null;this.src='https://a248.e.example.net/9e0d7c
`<img src="https://ext.example.com/conversion/?c=122959&a=30225" width="1" height="1" onerror="this.onerror=null;this.src='https://a248.e.example.net/9e0d7c940412d5badab847b855f8ac46.com/conv/'+this.src.substring(this.src.indexOf('?'));" />`
``
以下是我试图做的:
var lines = "<img src=";
var lines2="https://ext.example.com/conversion/?c=122959&a=30225";
var lines3=";this.src='https://a248.e.example.net/9e0d7c940412d5badab847b855f8ac46.com/conv/'+this.src.substring(this.src.indexOf('?'));";
setTimeout(function(){
document.write(lines+'"'+lines2+'" width="1" height="1" onerror="this.onerror=null'+lines3+'" />');
}, 10000);
var-lines=“”);
}, 10000);
我之所以使用变量,是因为-->'是一个纯JavaScript实现,它将在10秒后将跟踪像素附加到
window.onload = function() {
function addTrackingPixel() {
var pixel = document.createElement("IMG");
pixel.setAttribute("src", "https://ext.example.com/conversion/?c=122959&a=30225");
pixel.setAttribute("height", "1");
pixel.setAttribute("width", "1");
pixel.setAttribute("onerror", "this.onerror=null;this.src='https://a248.e.example.net/9e0d7c940412d5badab847b855f8ac46.com/conv/'+this.src.substring(this.src.indexOf('?'));");
document.body.appendChild(pixel);
}
var timeout = setTimeout(addTrackingPixel, 10000);
};
可能是格式不正确的HTML。例如,
src
值周围缺少引号。但Dan下面的示例更清晰,我同意这一点