location.href and onload

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • berg@nospam.invalid

    #1

    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.hr ef=urls[next_win++];
    }
    }

    Is this correct behavior?

    --
    -Mike
  • Randy Webb

    #2
    Re: location.href and onload

    berg@nospam.inv alid wrote:[color=blue]
    > I'm trying to use the onload event to load a series of urls.[/color]

    Thats fallible at best with the onslaught of popup blockers and browsers
    with built-in popup blockers.
    [color=blue]
    > What I find is that the onload function is only called one time
    > no matter how large the array.[/color]

    No, it is not "called", you are resetting it each time.
    [color=blue]
    > Here is the onload function.[/color]
    [color=blue]
    > var next_win = 0;
    > var win = window.open("", "", "");
    > function nextWin() {
    > if (next_win < urls.length) {
    > win.onload = nextWin;
    > win.location.hr ef=urls[next_win++];
    > }
    > }
    >
    > Is this correct behavior?[/color]

    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.javas cript FAQ - http://jibbering.com/faq

    Comment

    • berg@nospam.invalid

      #3
      Re: location.href and onload

      Randy Webb <HikksNotAtHome @aol.com> wrote:
      [color=blue]
      >berg@nospam.in valid wrote:[/color]
      [color=blue][color=green]
      >> What I find is that the onload function is only called one time
      >> no matter how large the array.[/color]
      >
      >No, it is not "called", you are resetting it each time.
      >[/color]

      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.
      [color=blue][color=green]
      >> 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.hr ef=urls[next_win++];
      >> }
      >> }
      >>
      >> Is this correct behavior?[/color]
      >
      >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.
      >[/color]
      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

      Comment

      • Lee

        #4
        Re: location.href and onload

        berg@nospam.inv alid said:
        [color=blue]
        >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.[/color]

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

        Comment

        • Robert

          #5
          Re: location.href and onload

          berg@nospam.inv alid wrote in message news:<r5_7d.188 7$M05.1292@news read3.news.pas. earthlink.net>. ..[color=blue]
          > Randy Webb <HikksNotAtHome @aol.com> wrote:
          >[color=green]
          > >berg@nospam.in valid wrote:[/color]
          >[color=green][color=darkred]
          > >> What I find is that the onload function is only called one time
          > >> no matter how large the array.[/color]
          > >
          > >No, it is not "called", you are resetting it each time.
          > >[/color]
          >
          > 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.[/color]

          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.

          [color=blue]
          > I guess I wasn't clear. First I call the nextWin function from the mainline
          > of the page.[/color]

          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.next Win(); ... ",
          "", /* 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.
          */
          "");

          [color=blue]
          > nextWin sets the onload event handler of the child window to
          > point at the parent's windows newtWin function[/color]

          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;
          [color=blue]
          > and loads a new url into
          > the child window.[/color]


          What you see is:
          [color=blue]
          > 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.[/color]


          /* 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.hr ef = 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.hr ef = 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(url s[i],"page" + i,"");
          }



          Robert

          Comment

          • berg@nospam.invalid

            #6
            Re: location.href and onload

            Lee <REM0VElbspamtr ap@cox.net> wrote:
            [color=blue]
            >berg@nospam.in valid said:
            >[color=green]
            >>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.[/color]
            >
            >When you load a new URL into a window, you clear any existing onload
            >handler, along with any other script.
            >[/color]

            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.loadi ng property but that doesn't seem to work as it is always
            false.

            --
            Thanks,
            Mike

            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: location.href and onload

              berg@nospam.inv alid wrote:
              ^^^^^^^^^^^^^^^ ^^^^[color=blue]
              > [...]
              > Is this correct behavior?[/color]

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


              PointedEars

              Comment

              • Randy Webb

                #8
                Re: location.href and onload

                Thomas 'PointedEars' Lahn wrote:[color=blue]
                > berg@nospam.inv alid wrote:
                > ^^^^^^^^^^^^^^^ ^^^^
                >[color=green]
                >>[...]
                >>Is this correct behavior?[/color]
                >
                >
                > No, it is not. See <http://www.earthlink.n et/about/policies/use/>,
                > section 2, paragraphs f and m.[/color]

                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.javas cript FAQ - http://jibbering.com/faq

                Comment

                • George Hester

                  #9
                  Re: location.href and onload

                  "Randy Webb" <HikksNotAtHome @aol.com> wrote in message news:6bydnT8JMe EORefcRVn-ow@comcast.com. ..

                  <snip>
                  [color=blue]
                  > Your move stupid.[/color]
                  [color=blue]
                  > --
                  > Randy
                  > comp.lang.javas cript FAQ - http://jibbering.com/faq[/color]

                  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 "intelligen t." Randy you are not intelligent. You
                  are shameful.

                  --
                  George Hester
                  _______________ _______________ ____

                  Comment

                  • Randy Webb

                    #10
                    Re: location.href and onload

                    George Hester wrote:
                    [color=blue]
                    > "Randy Webb" <HikksNotAtHome @aol.com> wrote in message news:6bydnT8JMe EORefcRVn-ow@comcast.com. ..
                    >
                    > <snip>
                    >
                    >[color=green]
                    >>Your move stupid.[/color]
                    >
                    >[color=green]
                    >>--
                    >>Randy
                    >>comp.lang.jav ascript FAQ - http://jibbering.com/faq[/color]
                    >
                    >
                    > 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 "intelligen t." Randy you are not intelligent. You
                    > are shameful.
                    >[/color]

                    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 "intelligen ce". 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.javas cript 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?

                    Comment

                    • George Hester

                      #11
                      Re: location.href and onload

                      "Randy Webb" <HikksNotAtHome @aol.com> wrote in message news:hZOdnbNiF5 t91OHcRVn-3A@comcast.com. ..[color=blue]
                      > George Hester wrote:
                      > [color=green]
                      > > "Randy Webb" <HikksNotAtHome @aol.com> wrote in message news:6bydnT8JMe EORefcRVn-ow@comcast.com. ..
                      > >
                      > > <snip>
                      > >
                      > > [color=darkred]
                      > >>Your move stupid.[/color]
                      > >
                      > > [color=darkred]
                      > >>--
                      > >>Randy
                      > >>comp.lang.jav ascript FAQ - http://jibbering.com/faq[/color]
                      > >
                      > > [/color][/color]
                      <snip>[color=blue][color=green]
                      > > [/color]
                      >
                      > 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.
                      >[/color]

                      A little humor can go a long way, eh?
                      [color=blue]
                      >
                      > 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 "intelligen ce". 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.javas cript 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?[/color]

                      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
                      _______________ _______________ ____

                      Comment

                      Working...