Open links, one after another

后端 未结 3 999
难免孤独
难免孤独 2021-01-23 10:43

I\'m making a website where I\'m opening a new window every 30 seconds. I got it to open the new windows properly, but I would like it to close the last window opened before ope

3条回答
  •  佛祖请我去吃肉
    2021-01-23 11:05

    You can use a string array to store all of the links, and then iterate through that loop calling open and close after 30 seconds. Using a loop and abstracting open/close allows you to have as many links as you'd like.

    var linkArray = ['http://www.wol.com', 'http://www.bol.com', 'http://lol.com', ['http://col.com']
    
    function openWin(link) { 
        var currentWindow = window.open(link);
        setTimeout(currentWindow.close(), 30000);
    }
    
    function runLinks() {
        for(var i = 0; i< linkArray.length; i++) {
              openWin(linkArray[i]);
        }
    }
    

提交回复
热议问题