How do I stop JQuery location.reload loading more than once? -


i running countdown clock. when countdown finishes. want refresh page once. using location.reload keeps loading , loading , loading. how break loop?

<script type="text/javascript">   $('#clock').countdown('<?php echo $tickets_pagerecord['sales_start_date']; ?>')   .on('update.countdown', function(event) {     var format = '%h hr%!h %m min%!m %s  sec%!s';     if(event.offset.totaldays > 0) {       format = '%-d day%!d ' + format;     }     if(event.offset.weeks > 0) {       format = '%-w week%!w ' + format;     }     $(this).html('box office opens in ');     $(this).append(event.strftime(format));   })   .on('finish.countdown', function(event) {     $(this).html('<h3>click on shopping cart buy tickets</h3>');     location.reload();   }); </script> 

you need pass state once have reloaded, don't run on again.

you can...

  1. add query string parameter tell script not run
  2. add flag 1 of storage options (cookie, local storage, etc) can check decide whether run script
  3. if page materially different (you refreshing because assume) test difference

but better - running php on server, if time has passed - don't add javascript don't need anymore (it looks refresh when box office open).


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -