You won't be able to intercept the image before it is loaded but you can
block it from being rendered.  Remember that JavaScript relies on the DOM.
The DOM isn't fully-defined for the page, until all of it has loaded.  But
you can hide it by setting its visibilitiy to "hidden", and keep the browser
from allocating real estate for it by setting "display" to "block". (Default
is "inline").

Looking at the code you included, I don't believe there is a statistic of
interest that you cannot collect when the page you've served, is requested.
(That is, the only info the browser will have that is new, it the location
of what it renders after receiving what the server sends.)  For example, the
location of everything won't be available to JavaScript until after what it
will render, has been rendered.

By the way, I'm not pretending I know your business.  What I meant by "stat
of interest" is that whatever you collect, after delivering the image, that
you cannot collect when the request for the page is made, is something that
can be assumed as consistent, from request to request, even from the same
user.

Correct me if I'm incorrect about this (please).

--John Crout


On Wed, May 20, 2009 at 9:51 AM, Andy Matthews <amatth...@dealerskins.com>wrote:

>
> Can I intercept the loading of an image BEFORE it loads?
>
> We're looking at using an img tag for inserting stats on our server. Here's
> what I'm considering...
>
> 1) Collect certain information server side, write an img to the document
> like so (note the URL vars):
>
> <img id="statsImg" src="stats.cfm?somevar=someval" width="1" height="1" />
>
> 2) Using JS, intercept the load of this image BEFORE it takes place, and
> add
> things to the URL vars.
>
> This way, if JS is not present, you get the default stuff, but if JS is
> present, you get extra stuff.
>
> Anyone?
>
> Andy Matthews
> Senior Web Developer
>
> www.dealerskins.com
>
> P Please consider the environment before printing this e-mail.
>
> Total customer satisfaction is my number 1 priority! If you are not
> completely satisfied with
> the service I have provided, please let me know right away so I can correct
> the problem,
> or notify my manager Aaron West at aw...@dealerskins.com.
>
>

Reply via email to