RSS Forums RSS
Please support our HTML and CSS advertiser: Lunarpages Web Hosting
Views: 1760 | Replies: 6 | Thread Tools  Display Modes
Reply
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Question onload wildcard?

  #1  
Jan 21st, 2007
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?

<body onload="popWindow();somefunction();"*"(); "*"();">

AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 989
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 6
Solved Threads: 52
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is online now Online
Posting Shark

Re: onload wildcard?

  #2  
Jan 21st, 2007
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 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..
Reply With Quote  
Join Date: May 2006
Location: New Jersey
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Rep Power: 5
Solved Threads: 34
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: onload wildcard?

  #3  
Jan 21st, 2007
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);
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: onload wildcard?

  #4  
Jan 21st, 2007
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>










Originally Posted by stymiee View Post
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);
Reply With Quote  
Join Date: May 2006
Location: New Jersey
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Rep Power: 5
Solved Threads: 34
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: onload wildcard?

  #5  
Jan 22nd, 2007
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!
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: onload wildcard?

  #6  
Jan 22nd, 2007
Thanks Again!
Reply With Quote  
Join Date: Jan 2008
Posts: 1
Reputation: sharonm is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sharonm sharonm is offline Offline
Newbie Poster

Question Re: onload wildcard?

  #7  
Jan 21st, 2008
Originally Posted by stymiee View Post
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!!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the HTML and CSS Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:04 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC