I generate a script for events, but when the time interval is too large, the function is called without delay. Code example:

setTimeout(function(){alert('hi')}, 2252124000); 

Has anyone encountered this problem? How can I get around it?

  • 3
    And to whom are you going to show in 26 days? - Anton Shchyrov
  • @Anton_Shcyrov In your opinion, who does not use the "pin tab"? Or all of you as mother asked, sat for an hour turned off a computer. - Makarenko_I_V
  • 2
    @Makarenko_I_V, in the above code, the alert is called before being sent to setTimeout - Grundy
  • one
    Can break setTimeout into 1000 laps with a while . Or, when the $(window).focus(function() {}) tab is activated $(window).focus(function() {}) , write the date / time variable into a variable when the user entered it to select the number of days from it compared to the previous date / time, compare it with the required number, and then show. And what has to do with the “fix the tab” - they just open automatically when the browser starts and not hang forever. - Andrew B

1 answer 1

I think the fact is that the maximum value of Signed Integer 32bit is 2 147 483 647 , you went beyond it

  • I think so too, but I ask if it is possible to get around this I'm in JS a layman, is there a long int or something else? - Makarenko_I_V
  • @Makarenko_I_V, this is at the browser engine level. For example, you can take the source code, for example chromium, change the type of the corresponding field and compile it - Grundy
  • 3
    @Makarenko_I_V, the problem is actually somewhat deeper than it seems at first glance. For such large intervals it is impossible to guarantee their exact performance. for this, at least, it is necessary that the page is constantly active, otherwise some browsers reduce the timer counter frequency, as a result it may work much later than expected, even if you use a trick divided into intervals of 2 ^ 31-1 - Grundy