Q:

javascript open & close multiple url with setInterval

I am trying to open multiple url in javascript for certain seconds and auto close them. I have no background knowledge in programming, just a little php. I am doing it to demonstrate a project.
I have an array with some url's.
var allURL = ["http://google.com", "http://yahoo.com", "http://msn.com"];

Now I want to open all url in new window/tab one by one for 10 seconds and auto close. So http://google.com opens for 10 seconds and auto close, then http://yahoo.com opens. Similar with all url's in array.
can you kindly guide me how can this be achieved using setInterval or any other ways. 

A:

var allURL = ["http://google.com","http://yahoo.com","http://msn.com"];

function showUrl(index) {
    index = index || 0;

    // are there any urls to show?
    // is the given index valid?
    if (allURL.length === 0 || index < 0 || index >= allURL.length) {
        return;
    }

    // open the url
    var popup = window.open(allURL[index]);

    // set a timer which closes the popup after 10 seconds and opens the next url by calling 'showUrl' with the next index
    setTimeout(function() {
        popup.close();
        showUrl(index + 1);
    }, 10000);
}

// To start the "diashow" call 'showUrl' without an index or if you want to start at a pre-defined url with the corresponding index
showUrl();    // starts with the first url

