Connecting Tech Pros Worldwide Forums | Help | Site Map

call js after page loads

uNConVeNtiOnAL
Guest
 
Posts: n/a
#1: Jul 20 '05
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

Stephen
Guest
 
Posts: n/a
#2: Jul 20 '05

re: call js after page loads


uNConVeNtiOnAL wrote:
[color=blue]
> 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
>[/color]

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>

Albert Wagner
Guest
 
Posts: n/a
#3: Jul 20 '05

re: call js after page loads


On Fri, 19 Sep 2003 16:01:41 -0500
uNConVeNtiOnAL <tomcat@visi.com> wrote:
[color=blue]
> 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 ???[/color]

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

George Ziniewicz
Guest
 
Posts: n/a
#4: Jul 20 '05

re: call js after page loads


"uNConVeNtiOnAL" <tomcat@visi.com> wrote in message
news:3F6B6EB5.723228A2@visi.com...[color=blue]
> 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 ???[/color]

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


Dr John Stockton
Guest
 
Posts: n/a
#5: Jul 20 '05

re: call js after page loads


JRS: In article <gUHbb.6714$gv5.96@fed1read05>, seen in
news:comp.lang.javascript, George Ziniewicz <zin1@cox.net> posted at
Mon, 22 Sep 2003 12:19:00 :-[color=blue]
>
> 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![/color]


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.
Closed Thread