Please support our HTML and CSS advertiser: Lunarpages Web Hosting
![]() |
supposing you had multiple scripts running, many remote hosted and you cant remember how many or which ones used a body onload tag.
Could you use a wildcard to cover them? for example, is something like this possible?
Could you use a wildcard to cover them? for example, is something like this possible?
<body onload="popWindow();somefunction();"*"(); "*"();">
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 989
Reputation:
Rep Power: 6
Solved Threads: 52
O_O
the wildcard * generally relates to everything. If that was possible, your code would be saying "call every function you can find, and pass no parameters".
it would be more handy if you could go halfway, like
But, unfortunately no. No such thing exists unless you implement it yourself.
The best way to manage such a thing is to append events to your body object from code rather than write them all in the onload attribute; that or call all of your onload functions from a single onload function.
the wildcard * generally relates to everything. If that was possible, your code would be saying "call every function you can find, and pass no parameters".
it would be more handy if you could go halfway, like
onload = "wildfnc('_onload*')" to execute all functions prefixed with _onload....But, unfortunately no. No such thing exists unless you implement it yourself.
The best way to manage such a thing is to append events to your body object from code rather than write them all in the onload attribute; that or call all of your onload functions from a single onload function.
Last edited by MattEvans : Jan 21st, 2007 at 2:12 pm.
Plato forgot the nullahedron..
•
•
Join Date: May 2006
Location: New Jersey
Posts: 1,422
Reputation:
Rep Power: 5
Solved Threads: 34
Using a single onload function is the best way to go. This javascript function allows you to keep adding functions to the onload event without having to worry about the ones already added:
Use like this to add a function to the onload event:
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function')
{
window.onload = func;
}
else
{
window.onload = function()
{
oldonload();
func();
}
}
}Use like this to add a function to the onload event:
addLoadEvent(functionName1); addLoadEvent(functionName2);
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Thankyou that looks easier! Do I need to add numbers and increment or just keep adding with a ';' at the end of each?
<script>
function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } }
addLoadEvent(popwindow);
addLoadEvent(spellchecker);
</script>•
•
•
•
Using a single onload function is the best way to go. This javascript function allows you to keep adding functions to the onload event without having to worry about the ones already added:
function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } }
Use like this to add a function to the onload event:
addLoadEvent(functionName1); addLoadEvent(functionName2);
•
•
Join Date: May 2006
Location: New Jersey
Posts: 1,422
Reputation:
Rep Power: 5
Solved Threads: 34
You have it perfect. Good luck.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
•
•
Join Date: Jan 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Using a single onload function is the best way to go. This javascript function allows you to keep adding functions to the onload event without having to worry about the ones already added:
function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } }
Use like this to add a function to the onload event:
addLoadEvent(functionName1); addLoadEvent(functionName2);
I hope you don't mind another post on this subject so long after the initial post. I found myself in need of a way to handle multiple onload functions and found your post.
I am NOT an experienced javascript coder, I just know enough to get by. This is further complicated by the fact that I'm a programmer, and need to be able to implement this within a perl script.
So, I'm a little confused about the addLoadEvnt(functionName1) statements to add additional functions to the onLoad. If all I'm putting in there is the name of a function, then where are all the actual functions stored for it to pull the actual code in? I have several "routines" - one is a Timer function that calls a secondary function; another is a function to try to disable certain Ctrl+key combinations that are causing major programming problems (it also calls one or more functions); and there is at least one more styleswitcher function that has its own window.onLoad calls.
If I put the primary function into the addLoadEvnt - then do I store that function, as well as the other functions that IT calls in a common javascript file pulled in via the <script type="text/javascript" ... statement at the top of the page?
I hope I'm making sense!!
![]() |
Similar Threads
Other Threads in the HTML and CSS Forum
- <Body onload= > question (HTML and CSS)
- body.onload += "XX" (JavaScript / DHTML / AJAX)
Other Threads in the HTML and CSS Forum
- Previous Thread: combining css menu's
- Next Thread: table in css
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode