473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

window.onload question

I have three functions I need triggered when page loads, so have

<body onload="function1();function2();function3()">

but I want to take all these function calls out of body tag and call
them in header, thus:

window.onload=function1;function2;

but I just realized that only first function in this list gets called
this way (if I put function2 first only function2 one gets called) also
noticed (http://scriptasylum.com/tutorials/pageevents.html) that when
you call functions this way you don't include '()'.. i.e., you do

window.onload=function1; // and not

window.onload=function1();

so how do you do it if you need to pass arguments to the functions(s)?

this is what I need to do:

window.onload=function1;function2;function3('arg') ;

but I can't get this to work...
(also noticed that onload is event handler of body, not window, so how
come get error on this: document.body.onload=function... etc.)

thank you..

Frances
Nov 2 '05 #1
3 1761
Frances wrote:
I have three functions I need triggered when page loads, so have

<body onload="function1();function2();function3()">

but I want to take all these function calls out of body tag and call
them in header, thus:

window.onload=function1;function2;

but I just realized that only first function in this list gets called
this way (if I put function2 first only function2 one gets called) also
noticed (http://scriptasylum.com/tutorials/pageevents.html) that when
you call functions this way you don't include '()'.. i.e., you do

window.onload=function1; // and not

window.onload=function1();

so how do you do it if you need to pass arguments to the functions(s)?

this is what I need to do:

window.onload=function1;function2;function3('arg') ;

but I can't get this to work...
(also noticed that onload is event handler of body, not window, so how
come get error on this: document.body.onload=function... etc.)

thank you..

Frances


actually, it's not event handler of body but of window.. so my question
should be: how come it works inside body tag? :)


Nov 2 '05 #2
Frances wrote:
I have three functions I need triggered when page loads, so have

<body onload="function1();function2();function3()">

but I want to take all these function calls out of body tag and call
them in header, thus:

window.onload=function1;function2; ^[1] but I just realized that only first function in this list gets called
this way


Of course. [1] The assignment ends at the first non-literal semicolon.
`function2' is evaluated as a reference then. It is the same as

window.onload = function1;
function2;

You need a wrapper function which is what the intrinsic event handler
attribute implements in the AOM:

window.onload = function()
{
function1();
function2();
function3();
};
PointedEars
Nov 2 '05 #3
Thomas 'PointedEars' Lahn wrote:
Frances wrote:

I have three functions I need triggered when page loads, so have

<body onload="function1();function2();function3()">

but I want to take all these function calls out of body tag and call
them in header, thus:

window.onload=function1;function2;


^[1]
but I just realized that only first function in this list gets called
this way

Of course. [1] The assignment ends at the first non-literal semicolon.
`function2' is evaluated as a reference then. It is the same as

window.onload = function1;
function2;

You need a wrapper function which is what the intrinsic event handler
attribute implements in the AOM:

window.onload = function()
{
function1();
function2();
function3();
};
PointedEars


thank you PointedEars......:)

Frances

Nov 2 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: HarveyB | last post by:
I would like to generate non-modal popup windows from ASP.Net code-behind. I have tried using Client Side scripting like "function Test(){ window.open('test.htm',_blank,...
6
by: Brian | last post by:
Hi everyone, I'm writing a function (in javascript) that needs to do one thing if the page has not loaded, and another (different) thing if the page has already loaded. I'm looking for a way...
2
by: Richard Bell | last post by:
I'm a bit new to Javascript and am trying to do oNewWin = window.open( ... ); then determine when the contents of oNewWin are completely loaded. I've tried oNewWin.attachEvent( "onload",...
3
by: Liming | last post by:
Hi, Here is my situation. I have a textarea on the page. When the page loads, I need it to have some default text (which will be generated dynamically) so I did something like this ...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
7
by: Q | last post by:
Question: why doesn't: window.onLoad = recalculate(); work, and do I have to use: window.onLoad = recalculate; (IE) ???
11
by: Dave | last post by:
For some reason, the below lines only work on select machines. All machines are running IE6. IE SP's and OS's vary. When it doesn't work, default.aspx (the page that this code is in) opens and...
6
by: Daz | last post by:
Hello everyone, I would like to open a child window from the parent, and add an onload event listener to the child window which will tell the parent when the document has loaded. As far as I...
20
by: Mark Anderson | last post by:
Hi, I have this in an external JS library: ///////////////////////// function addMyEvent(){ var obj; if(document.attachEvent) { obj = document.getElementsByTagName('img'); for...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.