View Full Version : Whats wrong with my script?!

01-12-2007, 09:55 AM
I need some help real quick, I posted a question a few hours ago about this but after a couple hours of tinkering I got it mostly done.

Below, arrays 0 thru 6 are the same web address. Array 7 is a different address. I need the script to open all seven one a couple seconds after another which it does, but I need it to close them after they have only been open about 5 seconds or open them all in the same window, which would be prefered. If they are opened in the same window they have to have time to load so the load of the next page needs to be delayed about 4 seconds or so.

Lastly, I need the script to loop over and over, prefererably around 5 times. Anyone want to point out my mistake on getting the window to close 5 seconds after it opens or getting it to open in the same window? Also getting the script to run 5 times in a row?

<SCRIPT language="JavaScript">
function display_go()
var go= new Array(8)
go[0]="website address 1";
go[1]="website address 1";
go[2]="website address 1";
go[3]="website address 1";
go[4]="website address 1";
go[5]="website address 1";
go[6]="website address 1";
go[7]="website address 2";
var x=0;
for (x=0; x<8; x++)
preview = window.open(go[x]);
setTimeout("preview.close();", 5000);
<BODY onLoad="display_go();">

01-12-2007, 03:48 PM
If those address values are not in your domain, you are not going to be able to close them. JavaScript will get a permission denied error.

I posted how to close multiple windows on my blog awhile back: http://radio.javaranch.com/pascarello/2005/01/19/1106152877000.html


01-12-2007, 09:27 PM
Well your script works better than mine. The only question I have is it possible to either A. Open them all in the same window? B. Is it possible to add a delay to the windows opening say 5 seconds between each other?

01-12-2007, 10:31 PM
Why do I have this feeling that you are doing this to annoy people? What is the point of the script? You do realize popup blockers will likely block the windows.

01-12-2007, 10:44 PM
Haha, no its not to annoy people, I promise. It's actually for myself. I am making to script to save myself some time. By opening a page a set number of times and then another page just once. If I wanted to annoy people I wouldn't want them to close themselves.. lol.

Can you offer me any advice?