473,405 Members | 2,185 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,405 software developers and data experts.

using OnLoad

PJ6
Say I have serveral controls, all of which need to emit clientside script to
execute on page load. They can't emit to OnLoad = <functionname> because
then only one of the scripts will get executed. Is there a way around this?

Paul
Sep 13 '05 #1
4 4522


PJ6 wrote:
Say I have serveral controls, all of which need to emit clientside script to
execute on page load. They can't emit to OnLoad = <functionname> because
then only one of the scripts will get executed. Is there a way around this?


Yes, but how easy you solve that depends on the browsers you target.
If you only look at W3C DOM Level 2 compatible ones like Mozilla and at
IE 5.5 and later on Win you have
if (typeof window.addEventListener != 'undefined') {
window.addEventListener(
'load',
yourFunction,
false
);
}
else if (typeof window.attachEvent != 'undefined') {
window.attachEvent(
'onload',
yourFunction
);
}
to be able to attach as meny different load handlers as needed from
different locations/scripts or in your case "several controls".

For older browsers not supporting addEventListener or attachEvent you
would then need to build your own mechanism e.g. set up and array
var loadHandlers = [];
each time a control needs to set up a handler you do e.g.
loadHandlers[loadHandlers.length] = yourFunction;
and then you need to make sure you have the following too
window.onload = function (evt) {
for (var i = 0; i < loadHandlers.length; i++) {
loadHandlers[i]();
}
};

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 13 '05 #2
"PJ6" <no****@nowhere.net> wrote in message
news:xxAVe.10322$c27.3429@trndny01...
Say I have serveral controls, all of which need to emit clientside script
to execute on page load. They can't emit to OnLoad = <functionname>
because then only one of the scripts will get executed. Is there a way
around this?


Is this what you meant?

<body onLoad="function1();function2();function3()">
Sep 13 '05 #3
PJ6
Hmmm. That looks like a good way to do it, too. I'd just have to access the
body html element and concatenate extra function names to the OnLoad
attribute, right? With a little work I could even code in some precedence,
like a z-index, only for methods.

Paul

"Danny@Kendal" <da***@STOPSPAMghpkendal.co.uk> wrote in message
news:A7*****************************************@e clipse.net.uk...
"PJ6" <no****@nowhere.net> wrote in message
news:xxAVe.10322$c27.3429@trndny01...
Say I have serveral controls, all of which need to emit clientside script
to execute on page load. They can't emit to OnLoad = <functionname>
because then only one of the scripts will get executed. Is there a way
around this?


Is this what you meant?

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

Sep 13 '05 #4
PJ6 wrote:

Top-posting is not liked here.
Hmmm. That looks like a good way to do it, too. I'd just have to access the
body html element and concatenate extra function names to the OnLoad
attribute, right? With a little work I could even code in some precedence,
like a z-index, only for methods.


What do you mean by access the onload attribute? If you mean doing it
on the server and changing the value of the body's onload attribute in
its HTML source, then you're OK. But you can't access the body's onload
attribute using something like:

alert( body.onload );

The value of the body's onload attribute is added to the window object,
you'll find your functions there:

<head><title>onload play</title>
<script type="text/javascript">
function sayHi(){}
</script>
</head>
<body onload="sayHi();">
<input type="button" value="Show body attributes" onclick="
var prop, i=0;
var txt = ['<b>Body attributes:</b>'];
for ( prop in document.body.attributes ) {
txt.push( i++ + ': ' + prop + ' : '
+ document.body.attributes[prop]);
}
if (window.onload){
txt.push('<br><b>window.onload:</b>',window.onload.toString());
}
document.getElementById('msg').innerHTML = txt.join('<br>');
">

<div id="msg"></div>
</body>
[...]
--
Rob
Sep 14 '05 #5

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

Similar topics

4
by: Pai | last post by:
hello there, I am trying to rersize the window it works find in IE but doea not work with mozilla window.attachEvent(onload,MWSOnLoad); window.onload = function (MWSOnLoad) { alert('hello');...
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...
4
by: David Virgil Hobbs | last post by:
My web host inserts banner ads into my html pages. The javascript in these banner ads interferes with the onload triggered javascript functions in my pages. Whether I trigger my javascript...
3
by: Russell | last post by:
I have a quirky issue that I believe involves timing and only 2 hairs left to pull. I have a modal dialog that is an IFrame. The IFrame contains another window - which contains the appropriate...
10
by: berg | last post by:
I'm trying to use the onload event to load a series of urls. What I find is that the onload function is only called one time no matter how large the array. Here is the onload function. var...
4
by: zborisau | last post by:
Hey good people, I've been given a problem to solve recently - and stuck with the solution for a good 4 days already. i have a link which leads to popup window. the purpose of that popup...
3
by: Vik Rubenfeld | last post by:
I'm working on integrating the a javascript wysiwyg editor (Xinha) with my blog software (ExpressionEngine, aka EE). EE has extensions now so it's easy to get the Xinha header code into the head...
6
by: tony | last post by:
Hello! When exactly is it important or advisable to use this form load event handler compare to using the C-tor. For example here I create an event handler called dataBoundGridForm that is...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.