Current location: Hot Scripts Forums » General Web Coding » JavaScript » Usine array elements with <img src= and document.write


Usine array elements with <img src= and document.write

Reply
  #1 (permalink)  
Old 12-28-04, 11:38 AM
tacuit tacuit is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Usine array elements with <img src= and document.write

Rather complex scenario here... I'm using several images rotating based on time of day. The images display fine.

<script language="JavaScript">
var layout = new Array;
layout[0] = "http://www.blabla.gif";
layout[1] = "http://wwwblabla.gif";
var digital = new Date();
var l = digital.getHours(24) % layout.length;

document.write("<img src=" + layout[l] + ">");

As only one image will display at any given time, I want to count the number of times each particular image is loaded.

<script language="JavaScript">
var advertisers = new Array;
advertisers[0] = "http://blabla/statistics/stat.php?id=blabla";
advertisers[1] = "http://blabla/statistics/stat.php?id=blabla";
var digital = new Date();
var l = digital.getHours(24) % advertisers.length;
var adhit = advertisers[l];

</script>

<img scr= "adhit" width="1" height="1">


If I use document.write(... to load the link to the stat counter for the image loaded, I get the blue ? icon on the page 'cos in fact there is no image, but the counter increments fine.

When I use <img src= with or without the " of the variable name and with or without the height and width, I cannot get the stat counter to increment the hit.

Any suggestions on either getting rid of the ? icon or getting the <img src to work ???

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 12-29-04, 02:43 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
You can combine those script tags into one.

Use
document.write("<img scr='"+adhit+"' width='1' height='1' style='width:0;height:0;visibility:hidden;display: none;'>
)

and place it inside the script tag to correctly insert the url before printing it out on the page while making sure that the ? icon isn't visible.
Reply With Quote
  #3 (permalink)  
Old 12-29-04, 06:02 PM
tacuit tacuit is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
*solved*

Thanks!! You can probably see the big grin on my face as I'm typing this reply
Reply With Quote
  #4 (permalink)  
Old 12-29-04, 09:16 PM
tacuit tacuit is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Here is the final code that hides the ? and gets a hit to the stats counter:

document.write("<img src='"+ advertisers[l] +"'style=visibility:hidden;'>");

Thanks to TwoD for getting my thinking going again
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 10:37 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.