How can i open 30 URLs one after another, each with 30 seconds of delay. Each new URL can be open in the same window or there could be one iframe where all URLs will be open, one after another.
-
1for open urls go :http://stackoverflow.com/questions/8454510/open-url-in-same-window-and-in-same-tab – Anand Dwivedi Aug 01 '15 at 05:49
3 Answers
Opening URLs in new tab windows. Set the time interval between loads using setInterval
.
Javascript Code :
var targets = [ //Place target URL here
'http://www.google.com',
'http://www.EnggForum.com/'
];
var iTarget;
function nextTarget(){
window.open( targets[iTarget], 'target' );
if( ++iTarget >= targets.length ) {
iTarget = 0;
}
}
function start() {
iTarget = 0;
nextTarget();
setInterval( nextTarget, 30000 ); //time interval here 30000 = 30 Sec
}

- 13,794
- 9
- 55
- 77
To execute any action on a repeated time loop, you can simply create a function that calls itself with a setTimeout. In this case, you would want it to call itself until it ran out of URLs to display.
To navigate an iFrame, you just set it's src property.
Combine those two answers and you have :
HTML:
<iframe id='the_iframe'></iframe>
JavaScript:
var urls = [
'https://www.youtube.com/embed/wZNYDzNGB-Q',
'https://www.youtube.com/embed/DRs0Kw2rUVQ',
'https://www.youtube.com/embed/JmENgrVOwgA',
'https://www.youtube.com/embed/2vEStDd6HVY'
];
var seconds = 30;
function openNext(){
document.getElementById('the_iframe').src = urls.shift();
if(urls.length)setTimeout('openNext()',seconds*1000);
}
openNext();
JsFiddle: http://jsfiddle.net/trex005/z09roapd/
It is also important to note that many websites set headers on their pages that do not allow them to be framed. If you need to use a popup instead, you can use all of the same logic here but you create your popup like this :
var popup = window.open(urls.shift();, 'popup');
And navigate it like this :
if(!popup.closed) {
popup.location.href = urls.shift();
}

- 5,015
- 4
- 28
- 41
check out the setTimeout and setInterval methods for JS Link1 and Link2
or try simple code
<!DOCTYPE html>
<html>
<body>
<p>Click the button to wait 3 seconds, then alert "Hello".</p>
<p>After clicking away the alert box, an new alert box will appear in 3 seconds. This goes on forever...</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
setInterval(function(){ alert("Hello"); }, 3000);
}
</script>
</body>
</html>

- 1,452
- 13
- 23