我需要一个JS在一定的时间间隔内按顺序显示网站。在下面的代码中,我希望它首先显示google for Xms,而不是NPR for Xms等等。我怎样才能实现
window.open("https://www.google.com","_self");
// wait Xms
window.open("http://www.npr.org","_self");
// wait Xms
window.open("https://www.washingtonpost.com","_self");
// wait Xms
window.open("https://www.google.com","_self");
// wait Xms
答案 0 :(得分:0)
var interval=2*1000; // 2 seconds
["https://www.google.com","http://www.npr.org","https://www.washingtonpost.com",
"https://www.google.com"].forEach((url,i)=>{
setTimeout(()=>{
window.open(url,'_self');
},interval*i);
})
interval * 0 = 0
interval * 1 = 2000
interval * 2 = 4000