Reputation: 137
Javascript array:
var urls = ['https://www.google.com', 'https://www.msn.com', 'https://stackoverflow.com'];
I am having the array of URLs. I want to open each URL every 15 seconds in a new tab or window.
function g(){
setTimeout(o, 1);
}
function o(){
window.open('page.php');
}
The above code is not working.
Upvotes: 1
Views: 345
Reputation: 1703
I think you are finding setInterval
.
var urls = ['https://www.google.com', 'https://www.msn.com', 'https://stackoverflow.com'];
var index = 0;
var interval = setInterval(o, 15000);
function o() {
if (typeof urls[index] !== typeof undefined) {
window.open(urls[index]);
index++;
} else {
clearInterval(interval);
}
}
Upvotes: 2