Click to See Complete Forum and Search --> : Removing IMG tag after page loads


Bullogna
02-08-2008, 12:48 PM
Hello all,

We track visits to our web page by putting an IMG tag on our page like this one:

<IMG width=1 height=1 SRC="http://###.xxx.com>

Nothing is actually downloaded or displayed on the page by this tag, obviously - we just log the calls to http://###.xxx.com to count the visits to the page.

Unfortunately, whenever someone uses Print or Print Preview (using IE at least), another call is made. Print Preview is particularly bad since any change to the layout in Print Preview mode will make another call. This greatly inflates our visit numbers.

One way I thought of to deal with this is to use JavaScript to somehow remove the IMG tag after the page loads. If so what would be the syntax for that? (I'm not too good with JavaScript yet so please spell it out.)

Any other possible solutions?

Thanks!

gil davis
02-08-2008, 01:52 PM
I don't think removing the image at the client would do any good. If using print causes a fetch, then the page is reloading in that process which will reset any JS code logic. Also, if a user disables JS you will get hits regardless of what you might try.

I believe the big boys use cookies accessed by the server, where it can't be turned off by the user.

Bullogna
02-08-2008, 02:57 PM
I should have mentioned that other objects on the page don't make similar calls when using Print or Print Preview, just this one (verified with Fiddler). I'm sure it's because this IMG tag doesn't actually pull an image from the server ... it just makes a call for nothing.

I also think this only happens with IE, but I'm not positive.

At any rate, I'd like to know if anyone knows how to remove an IMG tag after the page load (using the onload event somehow, I suppose) so I can test it out.

magentaplacenta
02-08-2008, 06:53 PM
<script type="text/javascript">
window.onload = function() {
var image = document.getElementsByTagName("img")[0];
image.style.display = "none";
}
</script>

<table border="1" cellpadding="6">
<tr valign="top">
<td align="center"><img src="http://www.google.com/intl/en_ALL/images/logo.gif"><br />No Google</td>
<td align="center"><img src="http://i.l.cnn.net/cnn/.element/img/2.0/global/nav/header/header_cnn_com_logo.gif"><br />CNN</td></tr>
</table>

Logic Ali
02-08-2008, 07:30 PM
I should have mentioned that other objects on the page don't make similar calls when using Print or Print Preview, just this one (verified with Fiddler). I'm sure it's because this IMG tag doesn't actually pull an image from the server ... it just makes a call for nothing.
Probably because the successful items are cached.
Something along these lines perhaps:
if(document.cookie && !document.cookie.match('mySiteSession'))
document.write('<img width=1 height=1 src="http://###.xxx.com">');
document.cookie='mySiteSession=true';