javascript - jQuery Countdown Timer for Games -
i need solid countdown timer queeze game, not easy hack.
i tried create own timer, sense fragile hacking:
var counter = 10; var timer = null; function countdown(){ if (counter == 10) { $(".time_box").html(counter); } if (counter <= 0) { stopinterval(); } else { counter--; $(".time_box").html(counter); } } function reset() { clearinterval(timer); counter=0; } function startinterval() { $(".time_box").html(counter); timer= setinterval("countdown()", 1000); } function stopinterval() { clearinterval(timer); } any ideas security improvments?
javascript not place security, 1 recommendation give cut down risk of user intervening encapsulate code cannot modified outside of object.
for illustration @ moment run next in browser console gain myself time:
counter = -99999 however if encapsulate logic counter isn't exposed wouldn't possible.
var myfunction = function(){ var counter = 10; var timer = null; function countdown(){ if (counter == 10) { $(".time_box").html(counter); } if (counter <= 0) { stopinterval(); } else { counter--; $(".time_box").html(counter); } } function reset() { clearinterval(timer); counter=0; } function startinterval() { $(".time_box").html(counter); timer= setinterval(countdown, 1000); } function stopinterval() { clearinterval(timer); } homecoming { startinterval: startinterval } }(); then phone call next start count down:
myfunction.startinterval(); now phone call counter in browser console wouldn't work, , neither myfunction.counter.
javascript jquery
No comments:
Post a Comment