Redirect multiple urls automatically.
Save the below code in the .html file and run it on the browser. The website will be refreshed automatically
<!DOCTYPE html>
<html>
<body>
<script>
//set the urls
var allURL = ["www.google.com","www.yahoo.com"];
var runtime=5,runtimeindex=0;
function showUrl(index) {
index = index || 0;
// are there any urls to show?
// is the given index valid?
if (index >= allURL.length) {
index = 0;
runtimeindex = runtimeindex + 1;
if (runtimeindex >= runtime)
return;
}
// open the url
var popup = window.open(allURL[index]);
// set a timer which closes the popup after 10 seconds and opens the next url by calling 'showUrl' with the next index
setTimeout(function() {
popup.close();
showUrl(index + 1);
}, 1000*60*1);
}
showUrl();
</script>
</body>
</html>
No comments:
Post a Comment