...

View Full Version : window.open - can I open it with a delay?



fail
01-20-2012, 01:50 AM
I do write some php, but have not much idea about JavaScript.

I use window.open to open 10 pages simultaneously. I prefer to open them with a time delay from each other to put less load on the target server. This is my code with no delay. (I played around with setTimeout but can't get it to work.)



<a href='http://www.".$new[9]."'
onclick=\"window.open('http://www.".$new[0]."/');
window.open('http://www.".$new[1]."/');
window.open('http://www.".$new[2]."/');
window.open('http://www.".$new[3]."/');
window.open('http://www.".$new[4]."/');
window.open('http://www.".$new[5]."/');
window.open('http://www.".$new[6]."/');
window.open('http://www.".$new[7]."/');
window.open('http://www.".$new[8]."/')\" target='new300/'>Open 10</a>

Dormilich
01-20-2012, 06:53 AM
I'm not sure if I, as a user of your website, would come again if a click on a link that opens 10 more pages. I'd find that highly annoying.

fail
01-20-2012, 10:16 AM
I'm not sure if I, as a user of your website, would come again if a click on a link that opens 10 more pages. I'd find that highly annoying.

I totally agree!

However, it's for a tool I wrote and strictly for my own use.

Dormilich
01-20-2012, 10:39 AM
you'll most probably won't come around a pure JS solution (meaning no inline-JS).

some idea

var wop = {
urls: [],
start: function() {
var urls = wop.urls.concat();
this.href = urls.pop();
wop.count = urls.length;
wop.open();
},
open: function() {
if (wop.count--) {
window.open(wop.urls[wop.count]);
window.setTimeout(wop.open, 1000);
}
}
}
<?php
printf("wop.urls = %s;", json_encode($news));
?>
document.getElementById("link").addEventListener("click", wop.start, true);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum