How to show the count down time Immediately?

http://www.scarvesonsale.com/index.php/sunflower-square-pure-silk-scarf.html

when i access the page, the count down time(the red part under the Special Price: ) not load Immediately.it run after some time. how to eliminate the delay time. thank you.

i use javascript onload

(window.onload = function() {)
event, but it maybe can’t effect. i don’t know why?

The onload event waits until everything on the page has finished loading, which is why you experience the long delay.

You have your code at the end of the page, which is a good thing, so replace this existing code:


window.onload = function() {
    if(_h<10){$('time_h').innerHTML = "0"+_h+":";}else{$('time_h').innerHTML = _h+":";}
    if(_m<10){$('time_m').innerHTML = "0"+_m+":";}else{$('time_m').innerHTML = _m+":";}
    if(_s<10){$('time_s').innerHTML = "0"+_s;}else{$('time_s').innerHTML = _s;}
    _t = setTimeout('doTime()', 1000); 
}

with this, which removes the onload event, and uses a more correct way to call the setTimeout:


if(_h<10){$('time_h').innerHTML = "0"+_h+":";}else{$('time_h').innerHTML = _h+":";}
if(_m<10){$('time_m').innerHTML = "0"+_m+":";}else{$('time_m').innerHTML = _m+":";}
if(_s<10){$('time_s').innerHTML = "0"+_s;}else{$('time_s').innerHTML = _s;}
_t = setTimeout(doTime, 1000); 

and things will work better.

You could even use a function that provides you with the leading zero, which helps to simplify the code to this:


function leadingZero(value) {
    return (value < 10) ? '0' + value : value;
}
$('time_h').innerHTML = leadingZero(_h) + ":";
$('time_m').innerHTML = leadingZero(_m) + ":";
$('time_s').innerHTML = leadingZero(_s);
_t = setTimeout(doTime, 1000); 

many thanks it works like a charm.