By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,259 Members | 1,680 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,259 IT Pros & Developers. It's quick & easy.

Sequence of Loading

P: n/a
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="JavaScript">
alert(tmp);
</script>

<script language="JavaScript" src="code.js"></script>

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

Aug 31 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
pk
<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
--------------

Aug 31 '05 #2

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

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

Aug 31 '05 #3

P: n/a
pk
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

Aug 31 '05 #4

P: n/a
pk
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?

Aug 31 '05 #5

P: n/a
mike wrote on 31 aug 2005 in comp.lang.javascript:
<SCRIPT FOR="window" EVENT="onLoad">
var tmp = "where are you";
</script>

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


loading and executing are not the same thing.

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

Aug 31 '05 #6

P: n/a
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.transformNode(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="JavaScript" 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="JavaScript">
function test(){}
</script>
then it ceased to produce the error and longer.

Aug 31 '05 #7

P: n/a
mike wrote:
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>


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

[...]

--
Rob
Sep 1 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.