我试图在一段时间后使用“ setTimeout”运行“ window.open”功能。如果我使用父项的属性计算时差,然后将输出用于“ setTimeout”,则“ window.open”函数将立即运行。但是,如果我给变量'diffms'一个数字,它就可以正常工作。 我正在使用反应,如何解决此问题?
// const diffms = 10000;
const diffms = moment(this.props.schedule.time).diff(moment());
setTimeout(() => {
window.open("https://www.google.com");
}, diffms);
答案 0 :(得分:1)
SetTimeout具有Maximum Delay Value
Internet Explorer,Chrome,Safari和Firefox等浏览器在内部将延迟存储为32位带符号整数。
当使用大于2147483483647毫秒(约24.8天)的延迟时,这会导致整数溢出,导致超时立即执行。
请在此处查看更多详细信息: