Sequence of Loading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mike

    Sequence of Loading

    I have a number of sources of javascript and don't really know the
    sequence of when each gets loaded.

    <SCRIPT FOR="window" EVENT="onLoad">
    var tmp = "where are you";
    </script>

    <script language="JavaS cript">
    alert(tmp);
    </script>

    <script language="JavaS cript" src="code.js"></script>

    Are they loaded based on the order they are seen in the page?

  • pk

    #2
    Re: Sequence of Loading

    <Excerpt from the HTML 4 specification>

    --------------
    18.2.4 Dynamic modification of documents

    1. All SCRIPT elements are evaluated in order as the document is loaded
    --------------

    Comment

    • mike

      #3
      Re: Sequence of Loading

      <SCRIPT FOR="window" EVENT="onLoad">
      var tmp = "where are you";
      </script>

      Apparently this does not load until after the document has finished
      loading, correct?

      Comment

      • pk

        #4
        Re: Sequence of Loading

        I believe so, and I could be way wrong since I don't work with
        JavaScript and the only reason I found myself in this newsgroup was
        because I had questions of my own. :) With that said,

        "The onload event occurs when the user agent finishes loading a window
        or all frames within a FRAMESET. This attribute may be used with BODY
        and FRAMESET elements. "

        My guess is that while you wouldn't see the effects of that particular
        javascript section until the window or all the frames finished loading,
        the code would still be processed first.

        Someone who knows should definitely comment though...

        -pk

        Comment

        • pk

          #5
          Re: Sequence of Loading

          It seems to me (now that I actually read your code to see what you're
          trying to accomplish), that the code as you have it now would put out
          an alert with the tmp variable which presumably holds garbage at this
          point. Then as the page finishes loading, it loads what you wish for
          it to print in the variable tmp, but never prints the alert again.

          Why do you have the delay on loading the string into the tmp variable?

          Comment

          • Evertjan.

            #6
            Re: Sequence of Loading

            mike wrote on 31 aug 2005 in comp.lang.javas cript:
            [color=blue]
            > <SCRIPT FOR="window" EVENT="onLoad">
            > var tmp = "where are you";
            > </script>
            >
            > Apparently this does not load until after the document has finished
            > loading, correct?
            >[/color]

            loading and executing are not the same thing.

            --
            Evertjan.
            The Netherlands.
            (Replace all crosses with dots in my emailaddress)

            Comment

            • mike

              #7
              Re: Sequence of Loading

              Reason for the question is I am applying an xml and xsl transformation
              so I wait for the document to be loaded before transforming it and
              rendering it in a <div id="stuff"></div> using something like
              stuff.innerHTML = src.transformNo de(sf); where src is the xml and sf is
              the xsl stylesheet.

              Another Reason is i had some code in a external file like: <script
              language="JavaS cript" src="code.js"></script> and I had a button with
              an onclick event that called a function in that external file. It
              produced an error when I clicked the button, but when I put that
              function embedded in the document like:
              <script language="JavaS cript">
              function test(){}
              </script>
              then it ceased to produce the error and longer.

              Comment

              • RobG

                #8
                Re: Sequence of Loading

                mike wrote:[color=blue]
                > I have a number of sources of javascript and don't really know the
                > sequence of when each gets loaded.
                >
                > <SCRIPT FOR="window" EVENT="onLoad">
                > var tmp = "where are you";
                > </script>[/color]

                It may be useful to know that for..event is IE only.

                [...]

                --
                Rob

                Comment

                Working...