Using new Image().src for click tracking

Posted by razass on Stack Overflow See other posts from Stack Overflow or by razass
Published on 2010-04-26T19:32:35Z Indexed on 2010/04/26 19:43 UTC
Read the original article Hit count: 246

Filed under:

I am attempting to figure out why this click tracker isn't working. The code was written by another developer so I am not entirely sure if this ever did work.

function trackSponsor(o, p) {
        (new Image()).src = PATH_BASE + 'click/' + p + '/' + o + "?_cache=" + (+(new Date()));
    return false;
}

From what I can gather is that when this function is called it 'creates a new image' to fire a php script asynchronously. According to Firebug, the request is made however it is 'aborted' ~30ms in. The odd thing is that it will 'sometimes' work as in 1 in every 10+ regardless of the browser.

I would much rather fix this so that it works instead of re-writing it as an ajax request.

Any help is appreciated.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about JavaScript