javascript - Countdown timer update on other window when i press pause on main window -
i have 1 window admin pannel can adjust time pause or stop countdown , window user seeing same timer. when press admin pannel on pause time or adjust time +- want user see time paused or adjusted. how can make that? tryed iframe doesnt change, try autoreload @ every 1 sec don't think that's good. want manipulate time window , show time on other window. can me this?
html
<div id="defaultcountdown"></div> <button type="button" id="pausebutton">pause</button> <button type="button" id="togglebutton">toggle</button>
js
<script> $(function () { var austday = new date(); austday = new date(austday.getfullyear() + 1, 1 - 1, 26); $('#defaultcountdown').countdown({until: austday}); $('#year').text(austday.getfullyear()); $('#defaultcountdown').countdown({until: austday, ontick: showpausetime}); $('#pausebutton').click(function() { var pause = $(this).text() === 'pause'; $(this).text(pause ? 'resume' : 'pause'); $('#defaultcountdown').countdown(pause ? 'pause' : 'resume'); }); $('#togglebutton').click(function() { $('#defaultcountdown').countdown('toggle'); }); function showpausetime(periods) { $('#showpausetime').text(periods[4] + ':' + twodigits(periods[5]) + ':' + twodigits(periods[6])); } }); </script>
what user seeing in window/tab
@abraar arique here code delayed 2-3 seconds
<?php header('content-type: text/event-stream'); header('cache-control: no-cache'); include_once('db.php'); $stmt=$dbh->prepare("select * mesaje game=0 order id_mesaj desc limit 1"); $stmt->execute(); if ($row=$stmt->fetch()) { $id_indiciu=$row['id_indiciu']; if ($row['id_indiciu']!=0) { $stmtt=$dbh->prepare("select * indiciu id_indiciu=$id_indiciu"); $stmtt->execute(); if ($rowz=$stmtt->fetch()) { echo "data: ".$rowz['indiciu']."\n\n "; } } else { echo "data: ".$row['mesaj']."\n\n "; } } ob_flush(); flush(); ?>
your trying create real time web app. these situations, making client looking information change every 1 second or inefficient. it's more common make server inform client changes client can update page accordingly. technique called server-sent events (sse). here, client-sever socket stays open , can transmit data , forth. best described using chatting web app facebook. on facebook when user logs in socket created. if sends message server-side script sends message event client , client shows message.
using server-sent events requires working knowledge of server-side scripting language: php, ruby, python, node.js, asp.net there many choose from. need use appropriate socket, websockets
example.
you need create server-side script listens timer changes , sends information browser (client). can use javascript update information whenever server-side script message received. may need design , implement database of kind if want save data.
one simple example of server-sent events: http://www.w3schools.com/html/html5_serversentevents.asp
hope answers question.
Comments
Post a Comment