{"id":701,"date":"2013-01-04T16:49:56","date_gmt":"2013-01-04T16:49:56","guid":{"rendered":"https:\/\/ibex.tech\/javascript\/?p=701"},"modified":"2022-02-17T07:14:47","modified_gmt":"2022-02-17T07:14:47","slug":"timers-general","status":"publish","type":"post","link":"https:\/\/ibex.tech\/javascript\/timers\/timers-general","title":{"rendered":"Timers General"},"content":{"rendered":"<h4>\nSimple Heartbeat Timer<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\/\/----- HEARTBEAT TIMER -----\r\nfunction heartbeat_timer_tick() {\r\n\r\n}\r\nsetInterval(&#39;heartbeat_timer_tick()&#39;, 1000 );\t\t \/\/Time in mS\r\n<\/code><\/pre>\n<p>\nNote that if the web browser tab is put in the background values of&nbsp;setInterval&nbsp;&lt; 1000 will be changed to 1000 by browsers such as chrome to improve performance for the active tab.\n<\/p>\n<h4>\nA Timer You Can Stop<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\/\/----- TIMER -----\r\nvar my_timer_count = 10;\r\nvar my_timer = setInterval(&#39;my_timer_tick()&#39;, 1000);\t\t \/\/Time in mS\r\n\r\nfunction my_timer_tick() {\r\n\tmy_timer_count = my_timer_count - 1;\r\n\t\r\n\tif (my_timer_count &lt;= 0)\r\n\t{\r\n\t\tdocument.getElementById(&#39;my_message&#39;).innerHTML = &quot;Competed&quot;;\r\n\t\tclearInterval(my_timer);\t\t\/\/Stop the timer\r\n\t\treturn;\r\n\t}\r\n\tdocument.getElementById(&#39;my_message&#39;).innerHTML = &quot;Seconds to go: &quot; + my_timer_count;\r\n}\r\n\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Simple Heartbeat Timer \/\/&#8212;&#8211; HEARTBEAT TIMER &#8212;&#8211; function heartbeat_timer_tick() { } setInterval(&#39;heartbeat_timer_tick()&#39;, 1000 ); \/\/Time in mS Note that if the web browser tab is put in the background values of&nbsp;setInterval&nbsp;&lt; 1000 will be changed to 1000 by browsers such as chrome to improve performance for the active tab. A Timer You Can Stop \/\/&#8212;&#8211; [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[78],"tags":[],"class_list":["post-701","post","type-post","status-publish","format-standard","hentry","category-timers"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/comments?post=701"}],"version-history":[{"count":6,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/701\/revisions"}],"predecessor-version":[{"id":1398,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/701\/revisions\/1398"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/media?parent=701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/categories?post=701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/tags?post=701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}