PDA

View Full Version : Modify URL opening code



daverunt
03-17-2014, 05:02 PM
Hi,

First post here as my javascript knowledge is abysmal. Hoping you can help.

I have the code below to open a web page in the array every 60 seconds.
However what I would like it to actually do is open each page for 60 seconds then close it.





var myPages=["http://www.google.com", "http://www.yahoo.co.uk", "http://www.bing.co.uk"],
i = -1;

(function f(){
i = (i + 1) % myPages.length;
wo=window.open(myPages[i]);
setTimeout(f, 60000);

})();

zealouss
03-22-2014, 09:57 AM
// I replied to this thread some days ago but my reply was not posted (may be I am a new user and dynamicdrive don't trust me much)
// Here is the code


<html>
<head>
<script type = "text/javascript">
var myTimer;
var myPages = ["http://www.google.com","http://www.yahoo.com", "http://alexa.com"]
var counter = 0;
timer(true);
function timer(bool){
//alert(bool);
if (bool) {
myTimer = setInterval(function(){
handleInterval();
},10000);
}else{
clearInterval(myTimer);
}
}

function handleInterval(){
if (counter >= myPages.length) counter = 0;
var myDoc = window.open(myPages[counter]);
counter++;
setTimeout(function(){myDoc.close()},10000);

}
</script>
</head>

<body>

<button onclick = "timer(true)">Start Timer</button>
<button onclick = "timer(false)">Stop Timer</button>


</body>
</html>

//Just put as many websites in array as so want
// It is currently set to 10 sec. You can change the time interval
//Please wait for 10 seconds. Each site will open and close automatically