![](/img/trans.png)
[英]Function runs immediately without setTimeout() in Javascript
[英]setTimeout runs function immediately
我正在嘗試在一段時間后使用“setTimeout”運行“window.open”function。 如果我用父屬性計算時間差,然后將 output 用於“setTimeout”,則“window.open”function 會立即運行。 但是,如果我只是給變量“diffms”一個數字,它就可以正常工作。 我正在使用反應,我該如何解決這個問題?
// const diffms = 10000;
const diffms = moment(this.props.schedule.time).diff(moment());
setTimeout(() => {
window.open("https://www.google.com");
}, diffms);
SetTimeout 具有Maximum Delay Value
包括 Internet Explorer、Chrome、Safari 和 Firefox 在內的瀏覽器在內部將延遲存儲為 32 位簽名的 integer。
當使用大於 2,147,483,647 毫秒(約 24.8 天)的延遲時,這會導致 integer 溢出,從而導致立即執行超時。
請在此處查看更多詳細信息:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.