be**@nospam.invalid wrote in message news:<r5*****************@newsread3.news.pas.earth link.net>...
Randy Webb <Hi************@aol.com> wrote:
be**@nospam.invalid wrote: What I find is that the onload function is only called one time
no matter how large the array.
No, it is not "called", you are resetting it each time.
I guess I wasn't clear. First I call the nextWin function from the mainline
of the page. nextWin sets the onload event handler of the child window to
point at the parent's windows newtWin function and loads a new url into
the child window. Upon completion of the load the parent's nextWin function
is called as expected. It proceeds to load the next url from the array.
Upon completion of the loading of the second url the onload event handler
nextWin function is not called.
Could you describe what you are trying to accomplish from a high level
perspective. We are lost down in the trees and cannot see the forest.
I think you have a problem with variable scoping. I think you are
assuming you have access to variables when you do not. Try putting in
alerts in the function nextWin to see what is the value of next_win.
Try making the variable names a little different: nextWinCount instead
of next_win.
I guess I wasn't clear. First I call the nextWin function from the mainline
of the page.
Which page is nextWin being called from: the parent or the child?
I assume you have this in the parent.
var win = window.open("","","");
nextWin();
Of course this is a race condition. It assume the child has not
been completely loaded before you call nexWin().
or maybe you mean this:
var win = window.open(
"javascript: ...;parent.nextWin(); ... ",
"", /* perhaps you need a different name here.
having the same name here will just
return the handle of the active window.
Not sure what a null does.
*/
"");
nextWin sets the onload event handler of the child window to
point at the parent's windows newtWin function
I do not thinks so. I'd assume that nextWin is in the child's
variable pool.
win.onload = nextWin;
I think you are assuming that nextWin references the nextWin in this
file, but
I'd think it would be the nextWin in the child's file.
I'd expect.
win.onload = parent.nextWin;
and loads a new url into
the child window.
What you see is:
Upon completion of the load the parent's nextWin function
is called as expected. It proceeds to load the next url from the array.
Upon completion of the loading of the second url the onload event handler
nextWin function is not called.
/* assume page0.html */
var next_win = 0;
var urls ["page1.html",
"page2.html",
"page3.html"];
var win = window.open("","","");
function nextWin() {
if (next_win < urls.length) {
/* Set the childs onload handler
Has nextWin been declared in the child?
The child page completes loading. The
browser will call nextWin. NextWin
is in the variable pool of the child
( this is my assumption. )
What is the purpose of this?
*/
win.onload = nextWin;
/* Change the childs href from urls []
Problem in what file have you
declared urls and next_win? */
win.location.href = urls[ next_win++ ];
/* I think there is a logic error here.
Variable win is the reference to the
child window. Variable win.onload must
be in the parent of the child. Variable
next_win must be in one place. */
}
}
/* let's assume that nextWin references
the same nextWin function in the same
variable pool */
win.onload = nextWin;
/* Now were are changing the page in the
child window to a new page.
When that page gets loaded, it will
want to load a new page. It seems you are
just loading one page after the other.
*/
win.location.href = urls[ next_win++ ];
maybe this is what you want:
/* assume page0.html */
var next_win = 0;
var urls ["page1.html",
"page2.html",
"page3.html"];
for (var i = 0; i < urls.length; i++)
{
var win = window.open(urls[i],"page" + i,"");
}
Robert