Why does my setTimeout speed up when I have multiple tabs open to my site?

被刻印的时光 ゝ 提交于 2019-12-04 05:25:00

That whole situation is very odd. The only scenario that's coming to mind where it makes any sense is one where the browser is trying to "smooth" the period of self-reinstating setTimeouts, same as for setInterval, and the code that's doing that actually confuses timers in different windows with each other.

I don't know if it's feasible, especially with Facebook involved, but an interesting test would be to give each instance a randomized name for the countDown function and see if that makes any difference, like:

<?php $timerTag = rand(1, 1000); ?>
function countDown<?php echo $timerTag ?>() {
  ...
  setTimeout(function() { countDown<? php echo $timerTag ?>() }, 1000);    
}

countDown<?php echo $timerTag ?>();

If this changes the observed behavior, that argues for the scenario I have in mind. (And possibly provides a way of addressing the problem.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!