473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Delay counter

Hi. Is there a way to delay a call to a page counter (ie. call to a
server script from an IMG tag) for the purpose to not lock the page
loading awaiting counter be displayed.

Maybe a setTimeout() launching an equivalent of "document.write", but
writing in a specific DIV ? Thanks in advance for your ideas.

Actually, the counter is called (without delay) like this :

<div id="count" style="position: absolute; visibility: visible; top:
20px; left: 20px; width: auto; height: auto; z-index: 5; cursor:
default"><img src="http://host.com/cgi-bin/counter.exe?color=red&font=
6"></div>
Nov 6 '05 #1
7 3403
VK

JellyON wrote:
Hi. Is there a way to delay a call to a page counter (ie. call to a
server script from an IMG tag) for the purpose to not lock the page
loading awaiting counter be displayed.

Maybe a setTimeout() launching an equivalent of "document.write", but
writing in a specific DIV ? Thanks in advance for your ideas.

Actually, the counter is called (without delay) like this :

<div id="count" style="position: absolute; visibility: visible; top:
20px; left: 20px; width: auto; height: auto; z-index: 5; cursor:
default"><img src="http://host.com/cgi-bin/counter.exe?color=red&font=
6"></div>


Rendering delay happens not because of a server call by itself - but
because the engine cannot allocate the image until the image header
(with width and height) is received. As a result it cannot allocate
(render) the whole <div>.

If say it's a 128x32 image then this would solve the problem:
<div id="count" style="position: absolute; visibility: visible; top:
20px; left: 20px; width: auto; height: auto; z-index: 5; cursor:
default"><img src="http://host.com/cgi-bin/counter.exe?color=red&font=
6" width="128" height="32"></div>

If you server script is *very* slow (so user will see a red crossed
"missing image" sign for a while), you can fix the situation by:

<div id="count" style="position: absolute; visibility: visible; top:
20px; left: 20px; width: auto; height: auto; z-index: 5; cursor:
default"><img src="TempTransparent.gif" width="128" height="32"
onload="
if (this.src='TempTransparent.gif') {
this.src='http://host.com/cgi-bin/counter.exe?color=red&font= 6';
}"></div>

Nov 6 '05 #2
VK
! Nasty typo !
Read:
if (this.src=='TempTransparent.gif') {
this.src='http://host.com/cgi-bin/counter.exe?color=red&font= 6';
}">

Nov 6 '05 #3
In article <11**********************@g14g2000cwa.googlegroups .com>,
sc**********@yahoo.com says...
! Nasty typo !
Read:
if (this.src=='TempTransparent.gif') {
this.src='http://host.com/cgi-bin/counter.exe?color=red&font= 6';
}">


Thanks a lot VK. I will try your piece of code asap.
Nov 6 '05 #4
In article <11**********************@g14g2000cwa.googlegroups .com>,
sc**********@yahoo.com says...
! Nasty typo !
Read:
if (this.src=='TempTransparent.gif') {
this.src='http://host.com/cgi-bin/counter.exe?color=red&font= 6';
}">


Well, it sounds right :-) I've just replaced the if by a

setTimeout(function(){this.src='http://host.com/cgi-bin/counter.exe?
color=red&font=6';});

because it's better for delaying counter call and I didn't seen the
reason why for testing "TempTransparent.gif" presence (obviously always
here). Maybe something I've missed ?

Well, now, it stay just a thing : I would like to display another DIV
(which contain a text like "Number of hits : ") only if counter call
succeeded. The question is not to know how to show the DIV (simply
change the visibility style attribute), but what to test. That is the
question !
Nov 6 '05 #5
VK

JellyON wrote:
Well, it sounds right :-) I've just replaced the if by a

setTimeout(function(){this.src='http://host.com/cgi-bin/counter.exe?
color=red&font=6';});

because it's better for delaying counter call and I didn't seen the
reason why for testing "TempTransparent.gif" presence (obviously always
here). Maybe something I've missed ?
I did not mean to test for "TempTransparent.gif". The idea was to have
TempTransparent.gif loaded right away so user does not see empty image
frame. And right upon the TempTransparent.gif load you request the
counter picture so it appears on the page when ready. setTimeout is an
option but why make things more difficult as they should be? ;-)
Well, now, it stay just a thing : I would like to display another DIV
(which contain a text like "Number of hits : ") only if counter call
succeeded. The question is not to know how to show the DIV (simply
change the visibility style attribute), but what to test. That is the
question !


Error event supported by images since Netscape 3 - what else?

The combined code could be:
....
<img name="myCounter" src="myTransparent.gif" width="128" height="32"

onload="
if (this.src == 'myTransparent.gif') {
this.src='http://host.com/cgi-bin/counter.exe?color=red&font=6';
this.failedToLoad=false;
}
else {
document.getElementById('myDiv').style.visibility = 'visible';
}"

onerror="
this.src='myOops.gif';
this.failedToLoad=true;"
/>
....

As you cannot predict when exactly the counter will arrive, you better
let counter itself to make your <DIV> to appear, not vice versa.

To check the situation *later* (is counter loaded? is div displayed?)
you can always check the custom property failedToLoad:
if (document.images['myCounter'].failedToLoad) {
// I got some problems
}

Unlikely in your case, but be careful with animated gif's: they produce
new "load" event on each animation cicle (a very old GIF98a bug which
will never be fixed now).

Also make sure that at least 'myOops.gif' is always available,
otherwise you'll put your script into onerror loop. It also can be
fixed programmatically, but easier and better simply to have this image
on your server.

Nov 6 '05 #6
In article <11*********************@z14g2000cwz.googlegroups. com>,
sc**********@yahoo.com says...
onload="
if (this.src == 'myTransparent.gif') {
this.src='http://host.com/cgi-bin/counter.exe?color=red&font=6';
this.failedToLoad=false;
}


OK, it works unless the "if (this.src == 'myTransparent.gif')" because
the myTransparent.gif image has not always time to load before the
onload event. Not sure about this diagnostic, but has to be tried less
tired (me). Good night !
Nov 6 '05 #7
JellyON said the following on 11/6/2005 5:34 AM:
Hi. Is there a way to delay a call to a page counter (ie. call to a
server script from an IMG tag) for the purpose to not lock the page
loading awaiting counter be displayed.
Display a transparent image temporarily. Use the window.onload (or body
onload) to trigger a function that will change the images src attribute
accordingly.
Maybe a setTimeout() launching an equivalent of "document.write", but
writing in a specific DIV ? Thanks in advance for your ideas.

Actually, the counter is called (without delay) like this :

<div id="count" style="position: absolute; visibility: visible; top:
20px; left: 20px; width: auto; height: auto; z-index: 5; cursor:
default"><img src="http://host.com/cgi-bin/counter.exe?color=red&font=
6"></div>

<img src="http://yourDomain.com/transparent.gif" name="counterImage"
width="##" height="##">

along with this script:

function changeCounterImage(){
document.images['counterImage'].src="http://host.com/cgi-bin/counter.exe?color=red&font=6";
}

window.onload = changeCounterImage;

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 6 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Wolfgang Kaml | last post by:
Hello All, I have been researching newsgroups and knowledgebase all morning and not found a solution that would solve the problem I have. I am having an ASP or ASPX web page that implement a...
11
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
14
by: Des L. Davis | last post by:
System: Dell PowerEdge Server with 3 GB RAM, 2.4 GHz Celeron Software: Microsoft SQL Server 2000 Enterprise running on Windows 2003 Server Software: Microsoft SQL Server 2000 Enterprise running on...
2
by: amos_s12 | last post by:
Hello everybody Is there a possibility to make a delay between two sql statements, namely one sql statement is performed, then there is a delay of some seconds and then rhe next statement is...
6
by: lucifer | last post by:
hi i need to insert delay in my program what function should i use the old delay is not supported by the VC6
7
by: mfeingold | last post by:
I am working on a system, which among other things includes a server and a ..net control sitting in an html page and connected to the server. I ran into a couple of problems, you guys might have...
9
by: krbyxtrm | last post by:
hello i have this profile for iterating empty vectors: +0.3us (microsecond) delay on intel pentium 2.4Ghz can this added delay to my application be reduced? i mean near zero delay, its very...
17
by: Amy | last post by:
Hi, I finished this script and for some reason there is a delay every so often in the timing. Sometimes it seems two take 2 seconds instead of 1. Can anyone see anything that would slow it down? I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.