javascript - Run a counter that is displayed on website -


i want run counter on end of website, counting. made javascript counter (http://directinvent.com/counter/) displays desired result, although resets whenever site loaded each individual user.

the idea simple enough. run counter end , display result live on front end. ideas on how can done?

the same way timer in javascript. store when start counter. recalulate result on every update (request). no need math every 1/10s. if nobody ask, useless.

basicly, :

long starttime = storetimefor(user); return (currenttimeinsec - starttimeinsec) * incrementationpersec 

with this, need store starttime each user (in database, file, or in cache if want). on reset, store currenttime again.

this how timer in lots of langage because incrementing value every seconds (using sleep(1000)) not precise since thread not running time, not alone on machine ;)

edit :

on client side, not call server, ask value store , math client same logic. using timeout math on , on every x ms. see how create timer in javascript if need, value calculate change here.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

Laravel mail error `Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [ #0]` -

C#.NET Oracle.ManagedDataAccess ConfigSchema.xsd -