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

call js after page loads

P: n/a
Hi -

I can't call my js until the page is loaded down to the </body> tag - is
there
something similar to body onload that I can use to automatically run the
script
just before the page is done loading ???

Thanks

Tom

Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
uNConVeNtiOnAL wrote:
Hi -

I can't call my js until the page is loaded down to the </body> tag - is
there
something similar to body onload that I can use to automatically run the
script
just before the page is done loading ???

Thanks

Tom


Just put <script></script> at whatever point you want the code to run.
Of course, you have to put some valid js between the <script>s :-).
Regards
Stephen

E.G.,

<html><head><title>Run before I finish Loading</title>
<script type="text/javascript">
alert ("I'm running before we finished loading!");
</script>
</head>
<body onload="alert('Now I\'m through loading!');">
<h1>Hello World</h1>
</body>
</html>

Jul 20 '05 #2

P: n/a
On Fri, 19 Sep 2003 16:01:41 -0500
uNConVeNtiOnAL <to****@visi.com> wrote:
Hi -

I can't call my js until the page is loaded down to the </body> tag -
is there
something similar to body onload that I can use to automatically run
the script
just before the page is done loading ???


I always have an initialize() function in the inline script that is
triggered by onload.

--
Don't you see that the whole aim of Newspeak is to narrow the range of
thought? In the end we shall make thoughtcrime literally impossible,
because there will be no words in which to express it.
-- George Orwell, 1984

Jul 20 '05 #3

P: n/a
"uNConVeNtiOnAL" <to****@visi.com> wrote in message
news:3F***************@visi.com...
Hi -

I can't call my js until the page is loaded down to the </body> tag - is
there
something similar to body onload that I can use to automatically run the
script
just before the page is done loading ???


My observations as a somewhat newbie:

Inline code before <body> gets executed as it is read.

<body onload="..."> code gets executed allegedly after the page is
loaded, but it hasn't allowed me to refer to body elements further down in
body, like later div id's, widget object's onclick handler setup when the
widget is self-generated via doc.writes, etc. (IE and Mozilla?)

Code just before </body> wrapped in a <script></script> pair is the best
place I've found to have code that works on all types of objects since
everything has been defined before "here", it is here I often call an init()
routine (if it doesn't create any new html widgets w/ doc/write which should
be done exactly where they need to appear in body).

The main thing I learned is that the html & javascript is read and
processed once, from top down, so all online code can only refer to elements
it has read beforehand. Only functions that are called later (event
handlers) can be placed anywhere and refer to anything, with the hope that
they are not activated before a slow loading page finishes!
zin -- http://www.zintel.com
Jul 20 '05 #4

P: n/a
JRS: In article <gUHbb.6714$gv5.96@fed1read05>, seen in
news:comp.lang.javascript, George Ziniewicz <zi**@cox.net> posted at
Mon, 22 Sep 2003 12:19:00 :-

The main thing I learned is that the html & javascript is read and
processed once, from top down, so all online code can only refer to elements
it has read beforehand. Only functions that are called later (event
handlers) can be placed anywhere and refer to anything, with the hope that
they are not activated before a slow loading page finishes!

You could, I believe, put at the beginning of the first script var U=0
and at the very end of the page U=1

Then your event handlers could each begin with

if (TS()) return false

with a

function TS() {
if (U=0) alert('Too Hasty')
return U=0 }

or similar. Untested.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.