2017-08-02 56 views

回答

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 
} 
+0

這是我想要的,只是一個問題,如果我想打開在同一時間兩個環節再拖延一下,然後接下來的兩個作品?我試着用'window.open('http://google.com');'但它不起作用。 – Abid

+0

您可以在'nextTarget()'中複製日誌。查看更新的答案。 –

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); 
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; 
 
}

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);

0

你可以使用類似這樣的東西。

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]); 
 
    } 
 
}