Javascript以特定时间间隔打开网址

时间:2017-08-02 16:39:38

标签: javascript

如何一个接一个地打开30个网址,每个网址延迟30秒。每个新URL都可以在相同或新窗口中打开。

5 个答案:

答案 0 :(得分:1)

let delay = 0;
const step = 30 * 1000;
const urls = Array(30).fill('https://google.com')

for (const url of urls) {
  setTimeout(() => window.open(url), delay);
  delay += step;
}

答案 1 :(得分:0)

这样的事情应该有效:

var urlList = [ <your URLS> ];
var count = 0;
var handle = setInterval( function() {
    // open your window here from urlList[count]
    (++count) >= urlList.length && (clearInterval(handle));
}, 500);

答案 2 :(得分:0)

您可以使用您所链接的确切答案进行小幅调整......

var targets = [ //Place target URL here
    'http://www.computer.com/',
    'https://www.yahoo.com',
    'http://www.google.com/',
    'http://www.kompyooter.com/'
];

var iTarget;
var iInterval;

function nextTarget(windowsToOpen){
    window.open( targets[iTarget], 'target' );
    windowsToOpen--;
    if( ++iTarget >= targets.length ) {
        clearInterval(iInterval);
        return;
    }
    if (windowsToOpen > 0) {
        return nextTarget(windowsToOpen);
    }
}

function start() {
    iTarget = 0;
    nextTarget(2);
    iInterval = setInterval( function() {nextTarget(2)}, 30000 );   //time interval here 30000 = 30 Sec
}

答案 3 :(得分:0)

var array = [
"https://www.google.com",
"https://www.facebook.com"
"https://jquery.com",
"https://twitter.com"
]

let x = 0;
setInterval(function(){
  if(x < array.length){
    window.open(array[x++]);
  }
}, 30000);

答案 4 :(得分:0)

你可以使用这样的东西。

&#13;
&#13;
setInterval(openUrl, 30000); 

 var url = ['https://google.com', 'https://yahoo.com']; // add your 30 URls here
function openUrl(){
for(var i = 0; i < url.length; i++) {
  window.open(url[i]);
  }
}
&#13;
&#13;
&#13;