Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I need a Free Javascript countdown timer that does not rely on client's computer

    Hello. Does anyone know where I can get a free javascript or flash countdown timer that:

    1) Does not depend on the client's computer time

    2) That does not have to be uploaded to a domain (I don't own any)

    3) That does not have to go in the <head> section of html

    I would like to use this on eBay. Just in case you are thinking that eBay does not accept javascript, it does. If the javascript contains certain elements, then eBay will not accept them. I have found a few online that work on eBay, but they all depend on the time the user has set on their computer.

  • #2
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Since Javascript is run client-side, this cannot be done with Javascript only. You can make an ajax call to a server that gives you a time, but then you're using server-side code. I'd guess eBay doesn't allow that anyway, so once more: cannot be done.

  • #3
    New Coder
    Join Date
    Feb 2010
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I believe eBay would allow the server side programming, because I have gotten flash countdown timers to work and those are loading / running the swf file from someone else's domain.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,300
    Thanks
    203
    Thanked 2,561 Times in 2,539 Posts
    Quote Originally Posted by rojocru View Post
    I believe eBay would allow the server side programming, because I have gotten flash countdown timers to work and those are loading / running the swf file from someone else's domain.
    If you have made server-side timers code work on eBay, what then is your question?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New Coder
    Join Date
    Feb 2010
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    They don't work independent of the computer time, which is why I asked the question. If I change the time on my computer and then refresh the page (for some I don't even have to refresh the page), the time shown on the countdown timer changes.

  • #6
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    If you query the time from a server-side script, it will not depend on the client. And you can execute that query through Javascript with an Ajax call. But you will just have to use some kind of server than you can query. Javascript alone cannot do it.

  • #7
    New Coder
    Join Date
    Feb 2010
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not sure where the confusion is coming from, but there seems to be some of it.

    When I mentioned server side, I also mentioned flash. The flash countdown timers that I have tried are loading an swf file from the same site I got the flash file. I have no idea how the swf file is programmed as I know nothing about programming in flash. All I know is that when I change the time on my computer, the countdown timer changes the number of hours left.

    Anyhow, this is where things stand:

    1) It's looking like eBay will not support any javascript that references a website. I tried a few, and that seems to be the problem in eBay rejecting it.

    2) I have found one free countdown timer code that allows one to specify his/her timezone. It still changes when I change the time on my computer (both have the same timezone--the code and my computer), but yet if I were to change the time zone on my computer, which also changes the time on my computer, the timer does not change.

    2a) Also, the timer counts up once it has finished. I would prefer it to simply showS 0's and if possible, though not necessary, for it to show a message after the time is up instead of 0's.

    The designer of the code has a basic and advanced version. What I want done is possible in the advanced version, but it seems like the only way to have it display a message is by using the meta tag which does in the head section of an html file, a section that I don't have access to.

    Below is the Basic Version of the code. I don't know if anyone can figure out how to get it to show 0's rather than count up after the time is up.


    Code:
    <script type="text/javascript" defer="defer">//<![CDATA[
    // Andrew Urquhart : CountDown Timer : http://andrewu.co.uk/clj/countdown/
    function CD_T(id,e){var n=new Date();CD_D(+n,id,e);setTimeout("if(typeof 
    
    CD_T=='function'){CD_T('"+id+"',"+e+")}",1100-n.getMilliseconds())};function CD_D(n,id,e){var ms=e-n;if(ms<=0) ms*=-1;var 
    
    d=Math.floor(ms/864E5);ms-=d*864E5;var h=Math.floor(ms/36E5);ms-=h*36E5;var m=Math.floor(ms/6E4);ms-=m*6E4;var 
    
    s=Math.floor(ms/1E3);if(CD_OBJS[id]){CD_OBJS[id].innerHTML=d+" day"+(d==1?" ":"s ")+CD_ZP(h)+"h "+CD_ZP(m)+"m 
    
    "+CD_ZP(s)+"s"}};function CD_ZP(i){return(i<10?"0"+i:i)};function CD_Init(){var pref="countdown";var 
    
    objH=1;if(document.getElementById||document.all){for(var i=1;objH;++i){var 
    
    id=pref+i;objH=document.getElementById?document.getElementById(id):document.all[id];if(objH&&(typeof 
    
    objH.innerHTML)!='undefined'){var s=objH.innerHTML;var 
    
    dt=CD_Parse(s);if(!isNaN(dt)){CD_OBJS[id]=objH;CD_T(id,dt.valueOf());if(objH.style){objH.style.visibility="visible"}}else 
    
    {objH.innerHTML=s+"<a href=\"http://andrewu.co.uk/clj/countdown/\" title=\"Countdown Error:Invalid date format used,check 
    
    documentation (see link)\">*</a>"}}}}};function CD_Parse(strDate){var 
    
    objReDte=/(\d{4})\-(\d{1,2})\-(\d{1,2})\s+(\d{1,2}):(\d{1,2}):(\d{0,2})\s+GMT([+\-])(\d{1,2}):?(\d{1,2})?/;if(strDate.match(objReDt
    
    e)){var d=new Date(0);d.setUTCFullYear(+RegExp.$1,+RegExp.$2-1,+RegExp.$3);d.setUTCHours(+RegExp.$4,+RegExp.$5,+RegExp.$6);var 
    
    tzs=(RegExp.$7=="-"?-1:1);var tzh=+RegExp.$8;var 
    
    tzm=+RegExp.$9;if(tzh){d.setUTCHours(d.getUTCHours()-tzh*tzs)}if(tzm){d.setUTCMinutes(d.getUTCMinutes()-tzm*tzs)};return d}else 
    
    {return NaN}};var CD_OBJS=new Object();if(window.attachEvent){window.attachEvent('onload',CD_Init)}else 
    
    if(window.addEventListener){window.addEventListener("load",CD_Init,false)}else {window.onload=CD_Init};
    //]]>
    </script>
    The advanced version, in which one can definitely have the counter stop at 0 and also display a message, and the code can be found here: http://andrewu.co.uk/clj/countdown/pro/ The code, available for download, would go after the first <script type ...> line and before the last two lines (i.e. //]=]=> (the second to last line)
    </script> (the last line).

  • #8
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    Code:
    http://json-time.appspot.com/time.json?callback=serverTime
    __________
    serverTime({
      "tz": "UTC", 
      "hour": 9, 
      "datetime": "Sat, 06 Dec 2008 09:50:42 +0000", 
      "second": 42, 
      "error": false, 
      "minute": 50
    })
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #9
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    @ rnd_me

    Correct me if I'm missing something, but that would include querying a server.

    @ rojocru

    Being independ of the client's time and being independent of the client's time zone are completely different things. You could've said that to begin with.

    Anyhow. A simple solution is to replace

    Code:
    if(ms<=0) ms*=-1;
    with

    Code:
    if(ms<=0){CD_T=null;return;}

  • #10
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    Quote Originally Posted by Airblader View Post
    @ rnd_me
    Correct me if I'm missing something, but that would include querying a server.
    not in the context mentioned. it's obvious that you can't run, say, a php file that spits out the time. It's not obvious that you cannot use jsonp in general, and in fact, many of the existing scripts on ebay do just that.

    since all you need to do is inject the script and the callback will do the rest, i don't see how this is stoppable. If javascript runs, it's runs. I had no problem injecting the script in through the console, so ebays doesn't re-write things like document.createElement, so the machinery works.

    About all they can do is static analysys on the file, which is weak sauce. All you need to do to over-come that is compress the script using an eval-based compressor. dean edward's packer is one popular option. You can also use one of my slim routines, packer, or a zip-based packer at http://danml.com.slim/. This should hide the code from a robot censor, if one indeed exists.


    if, for some reason, you still can't call outside ebay, something else you can do is fetch a local url (just about any will work) using ajax, and use
    the data to create a local date object set to the server's time. From there, you just subtract the client's time to calculate a client offset, in ms.


    ex:

    Code:
    var x=new window['XMLHttp' + "Request"]();
    x.onload=function(){alert(new Date(x.getResponseHeader("Date")))};
    x.open("GET",location.href,false);
    x.send();
    code tested in chrome at codingforums.com and at ebay.com.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #11
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    I wasn't aware of what eBay allows and what not. So if a call to a json source works, that's probably the best bet.

    However, just assuming that eBay forbids calling any external url, any kind of workaround would be considered a violation of the terms of service (or whatever document contains those rules). I don't think we should be giving tips on how to overcome policies. Luckily, in this case it seems to be only an assumption. This is just a general thought.

  • #12
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    Quote Originally Posted by Airblader View Post
    However, just assuming that eBay forbids calling any external url, any kind of workaround would be considered a violation of the terms of service (or whatever document contains those rules). I don't think we should be giving tips on how to overcome policies. Luckily, in this case it seems to be only an assumption. This is just a general thought.
    i provide javascript advice, not legal advice. if in doubt, it behooves the OP to consult the EULA. My concern is really "can it be done", not should it, within reason.
    If a request is obviously shady, i won't help, but this one seems innocent enough...

    also, i forgot to mention. in many browsers, the server-sent Last-Modified head of the HTML page is available as document.lastModified. This is PROBABLY the same as Date on most dynamically-generated pages, and needs no ajax or external pings.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #13
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,572
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    Not to ask a silly question, but...

    Since EBay provides a countdown timer on every auction page (with a degree of precision that depends on how close the auction is to ending), why not just use JS code to find that timer and base your own code on it?

    Granted, if it's still 7 days to the end of the auction, EBay will probably just give you number of days and hours.

    But for any time under a day, EBay provides the number of hours, minutes, and seconds left. So you can start your timer from that.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •