Use a <noscript> tag for the non-JavaScript case, and a <script> tag with document.write() for the JavaScript case:
<noscript>
<img id="statsImg" src="stats.cfm?somevar=someval" width="1"
height="1" />
</noscript>
<script type="text/javascript">
document.write(
'<img id="statsImg" src="stats.cfm?somevar=someval&',
/* your extra stuff here, e.g.: */ 'anothervar=anotherval',
'" width="1" height="1" />'
);
</script>
-Mike
> _____________________________________________
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Andy Matthews
> Sent: Wednesday, May 20, 2009 8:52 AM
> To: [email protected]
> Subject: [jQuery] SOT: execute JS before a specific image loads
>
>
> 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?
>
<<attachment: winmail.dat>>

