Sunday 15 July 2012

javascript countdown synchronize on different browsers -


I'm sorry, if this question is a bit difficult, but I have no other way to ask it and I have a complete Not JavaScript in the world

I have this JavaScript counter that someone helped me to collect on the StackViewflow and it works fine but the countdown timer will start from the beginning on a different browser.

When I see it on Firefox, it will count down and it will continue to work as much as we want we say that the timer is set to countdown one day. It will save 23:24 hours / minute on Firefox, but if I open a new browser (any browser), then this timer will save 23:59 hours / min and it will start counting from there ... yet Counterdown timer was already running on the same page !!

Here is the code:

  & lt; Script type = "text / javascript" & gt; Var EXPIRY = parseInt (new date). GetTime () / 1000) + 24 * 60 * 60; Var Counter = Faucet; Var counter_interval = null; Function set cookie (name, value, day) {console.log ("setting" + name + "" + value); Termination of the year; If (day) {var date = new date (); Date.setTime (date.getTime () + (Days * 24 * 60 * 60 * 1000)); Ends = "; expires =" + date.toGMTString (); } And {end; = ""; } Document.cookie = name + "=" + value + finished + "path = /"; } GetCookie function (name) {var nameEQ = name + "="; Var ca = document.cookie.split (';'); For (var i = 0; i & lt; ca.length; i ++) {var c = ca [i]; While (c.charAt (0) == '') {c = c.svstring (1, c.length); } If (c.indexOf (nameEQ) === 0) {return c.substring (nameEQ.length, c.length); }} Return tap; } Function deleteCookie (name) {setCookie (name, "", - 1); } Function resetCounter () {EXPIRY = parseInt (new date). GetTime () / 1000) + 24 * 60 * 60; } Stopper () {window.clearInterval (counter_interval); DeleteCookie ('termination'); } Function updateCounter () {var msg = ''; Curium = purseInt (new date). Meet-time () / 1000); If (Curtimes & lt; EXPIRY) {msg = ConvertSeconds (EXPIRY - curtime); } And {EXPIRY = parseInt (new date). GetTime () / 1000) + 24 * 60 * 60; } Var el = document.getElementById ('counter'); If (L) {el.innerHTML = msg}} function convert from canttoode (sec) {var day, hour, rim, minute, second; Day = purse (sec / (24 * 3600)); Rim = sec - day * 3600 hours = persian (rim / 3600); Rem = rem-hours * 3600; Mins = parseInt (rim / 60); Secs = rem - mins * 60; Return day + ":" + hour + ":" + minute + ":" + seconds + ""; } Function startCounter () {stopCounter (); SetCookie ('End', EXPIRY, 1); Counter_interval = window.setInterval (Update Counter, 1000); } Function init () {EXPIRY = getCookie ('termination'); If (! EXPIRY) {console.log ("Unable to find cookie"); reset counter(); } Startcounter (); } in this(); & Lt; / Script & gt;   

You can see here at Bela:

How can I create it that it will save all browsers at the same time as it will be displayed on the same page can be done?

Thanks

Edit:

I found this code that works with mysql. It works fine but instead of count down, it will show how many days / hours / minutes the product / item was posted on the site. And there is no javascript required for this ...

What kind of searches I'm looking for but instead of counting it requires a countdown:

  & Lt; Php // list fields and seconds $ countdown ['days'] = (5) * convert to 24 * 60 * 60; $ Countdown ['hours'] = (3) * 60 * 60; // etc, etc. $ countsum = time () + $ countdown ['day'] + $ countdown ['hours']; // and so on // timestamp to enter the table above ########## Includes "config / connect_to_mysql.php" in the query 'dumbed down'; $ Result = mysql_query ("SELECT * tomProduct WHERE id = 'id';"); While ($ line = mysql_fetch_assoc ($ result)) $ time = $ line ['date_added'] - time (); // This field will be a php timestamp (time ()) $ count = getdate ($ time); $ X = getdate (); // Today's information is $ count ['mday'] - = $ x ['mday']; $ Count ['hour'] - = $ x ['mday']; $ Count ['min'] - = $ x ['min']; Echo "count of $ count [mday] day [hour] hour calculation $ min [minutes] minute"; // etc // unchecked, but should work? & Gt;  

Javascript is always running on the client The other example is no knowledge .

To synchronize the time between different browsers, you will need server-side scripts Using the Expression-Time-Stamp in a server-side script combining JavaScript with timer to give you that synchronization What you are looking for

No comments:

Post a Comment