Sequence of Loading

M

mike

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?
 
M

mike

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

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

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
 
P

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?
 
E

Evertjan.

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.
 
M

mike

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.
 
R

RobG

mike said:
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.

[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top