469,354 Members | 2,046 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,354 developers. It's quick & easy.

location.href and onload

I'm trying to use the onload event to load a series of urls.
What I find is that the onload function is only called one time
no matter how large the array.
Here is the onload function.

var next_win = 0;
var win = window.open("", "", "");
function nextWin() {
if (next_win < urls.length) {
win.onload = nextWin;
win.location.href=urls[next_win++];
}
}

Is this correct behavior?

--
-Mike
Jul 23 '05 #1
10 8682
be**@nospam.invalid wrote:
I'm trying to use the onload event to load a series of urls.
Thats fallible at best with the onslaught of popup blockers and browsers
with built-in popup blockers.
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.
Here is the onload function. var next_win = 0;
var win = window.open("", "", "");
function nextWin() {
if (next_win < urls.length) {
win.onload = nextWin;
win.location.href=urls[next_win++];
}
}

Is this correct behavior?


For the way you have it written, yes its correct. If you want to
repeatedly call a function, then explicitly call the function. But the
way you have it written, if it *did* call it repeatedly, it would be in
an endless loop until it kills the browser.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
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.
Here is the onload function.

var next_win = 0;
var win = window.open("", "", "");
function nextWin() {
if (next_win < urls.length) {
win.onload = nextWin;
win.location.href=urls[next_win++];
}
}

Is this correct behavior?


For the way you have it written, yes its correct. If you want to
repeatedly call a function, then explicitly call the function. But the
way you have it written, if it *did* call it repeatedly, it would be in
an endless loop until it kills the browser.

You seem to believe that the line "win.onload = nextWin" calls the nextWin
function. I believe it just sets the onload event handler.

--
Thanks,
Mike
Jul 23 '05 #3
Lee
be**@nospam.invalid said:
nextWin sets the onload event handler of the child window to
point at the parent's windows nextWin function and loads a new url into
the child window.


When you load a new URL into a window, you clear any existing onload
handler, along with any other script.

Jul 23 '05 #4
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
Jul 23 '05 #5
Lee <RE**************@cox.net> wrote:
be**@nospam.invalid said:
nextWin sets the onload event handler of the child window to
point at the parent's windows nextWin function and loads a new url into
the child window.


When you load a new URL into a window, you clear any existing onload
handler, along with any other script.


That's probably what's happening, although it's strange that it works
okay consistently the first time when nextWin is called from the
parent context and fails consistently when nextWin is called as
the child context onload handler.

What I'm trying to do is call a function in the parent window when the
child window completes loading. I have no control over the content of
the child window so I can't add the onload handler there. I do know
that the url is in the same domain as the parent window. I tried polling
child_win.loading property but that doesn't seem to work as it is always
false.

--
Thanks,
Mike
Jul 23 '05 #6
be**@nospam.invalid wrote:
^^^^^^^^^^^^^^^^^^^
[...]
Is this correct behavior?


No, it is not. See <http://www.earthlink.net/about/policies/use/>,
section 2, paragraphs f and m.
PointedEars
Jul 23 '05 #7
Thomas 'PointedEars' Lahn wrote:
be**@nospam.invalid wrote:
^^^^^^^^^^^^^^^^^^^
[...]
Is this correct behavior?

No, it is not. See <http://www.earthlink.net/about/policies/use/>,
section 2, paragraphs f and m.


From your cited paragraph f:

Using deliberately misleading headers ("munging" headers) in news
postings in order to avoid spam email address collectors is allowed.
^^^^^^^^^^
Nothing in Paragraph M associates directly to what you are babbling about.

Your move stupid.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #8
"Randy Webb" <Hi************@aol.com> wrote in message news:6b********************@comcast.com...

<snip>
Your move stupid. --
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq


What is wrong with this character? I have never seen someone so persistent in babbling about how everyone
else is nothing but "stupid" whereas Randy (yes you) is so clearly "intelligent." Randy you are not intelligent. You
are shameful.

--
George Hester
__________________________________
Jul 23 '05 #9
George Hester wrote:
"Randy Webb" <Hi************@aol.com> wrote in message news:6b********************@comcast.com...

<snip>

Your move stupid.


--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq

What is wrong with this character? I have never seen someone so persistent
in babbling about how everyone else is nothing but "stupid" whereas Randy
(yes you) is so clearly "intelligent." Randy you are not intelligent. You
are shameful.


Considering that you replied to a message that I attempted to cancel, I
find it half-funny. But coming from you, its totally 100% hilarious.

Me being "shameful" when it comes to PointedHead, it comes from me
putting up with his obnoxious half-baked arguments over and over and
over. This thread is a very good example of his "intelligence". If you
can explain the intents/purposes of replying to a thread that is three
weeks old since the last post, it *might* make sense.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Jul 23 '05 #10
"Randy Webb" <Hi************@aol.com> wrote in message news:hZ********************@comcast.com...
George Hester wrote:
"Randy Webb" <Hi************@aol.com> wrote in message news:6b********************@comcast.com...

<snip>

Your move stupid.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq


<snip>


Considering that you replied to a message that I attempted to cancel, I
find it half-funny. But coming from you, its totally 100% hilarious.


A little humor can go a long way, eh?

Me being "shameful" when it comes to PointedHead, it comes from me
putting up with his obnoxious half-baked arguments over and over and
over. This thread is a very good example of his "intelligence". If you
can explain the intents/purposes of replying to a thread that is three
weeks old since the last post, it *might* make sense.


--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?


Randy OK. Life is too short to quibble with people. I don't want to get into that with you.
But man calling people names or using snide comments to make how you feel about others clear
serves no purpose. What do you hope to achieve by doing that? Thomas has given trusted and good info in the past as well as you. But one thing I have never seen him do is call people names. I'm not an angel's bra strap either but c'mon. If you feel the urge to wail on others well I hope you don't do it to your wife. You probably have a sense of constraint there try here. I know I'd like you much better.

--
George Hester
__________________________________
Jul 23 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Konrad Mathieu | last post: by
1 post views Thread by solutions | last post: by
8 posts views Thread by gowens | last post: by
6 posts views Thread by August Karlstrom | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.