473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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 9350
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steven | last post by:
All I want to pop up a window before/during redirect to another page. Sort of a confirmation page: <? .... /* I need to pop up a window here */
2
by: Konrad Mathieu | last post by:
Does this work in most browsers, namely MSIE? document.links.href or does it have to be document.links.href ?
8
by: Phil Powell | last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href = document.location.href.substring(0, document.location.href.indexOf('?')); if (document.location.href.indexOf('#') >= 0) {...
1
by: JF | last post by:
Hi, I need to change the location of the parent window and after that scroll a little bit (because of "position:fixed" css buttons, which obscure the title). I have...
1
by: solutions | last post by:
Hi, Here is my relevant code for an arbitrary page (let's call it PAGE_B): <body onload="window.location.hash='anchor';"> With this code, if the user goes from PAGE_A to PAGE_B, he will jump...
2
by: crwng | last post by:
Hi. I'm trying to forward my web site users to a more friendly error message whenever they encounter a 404 page not found error. So far, it's been working fine...until XP SP2 came onto the...
8
by: gowens | last post by:
I have a page that contains several HREFs. Each HREF that I'm interested in has a common parameter (parmX). Does anyone have a script example on how to find-and-replace parmX with parmY? I'm...
4
by: petermichaux | last post by:
Hi, I'm hoping for a reason I'm wrong or an alternate solution... I'd like to be able to dynamically include some javascript files. This is like scriptaculous.js library but their solution is...
6
by: August Karlstrom | last post by:
Hi everyone, I have some problems loading a page into a frame from a different frame. In Firefox and Explorer the lower frame displays "Test..." but in some older version of Safari it is left...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.