Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Instead of using <body onload>

    Hi, instead of using <body onLoad="goforit()"> command to call up a script that runs at Page load up. Is there another command that I can put into the <Script> </Script> section to run upon page load..? Thanks.

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Two choices:

    Pointer:

    function onload_function() {
    //statements
    }

    onload = onload_function; //no parentheses

    ...or literal:

    onload = function() {
    //statements
    }

    Either one, inside a <script></script> block (or external .js file), anywhere in your page..

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not a good idea to do it this way. That's how get scripts that do not work together.
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There's a simple solution to that: understand what's going on in your page!

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    If u have two ore more scripts whose functions are called on onload (if this is your problem...?), you can do it in 3 methods:

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

    2. put al the onload function in one of the scripts (say script1), like this:

    .
    .
    .
    onload = init() {
    function1();
    function2();
    function3();
    }

    or another syntax is

    onload = init;
    function init() {
    function1();
    function2();
    function3();
    }


    !! but don't forget to erase the onload functions from the other 2 scripts (in our case, script 2 and script2) !!

    3. use the same function as above, but put it in a separate JS file, callled, say, onload.js and called that JS file from head,

    <script language="JavaScript" src="script/onload.js"></script>

    You can run now a different number of scripts with functions called on onload...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm working on a cross-browser event queue manager, whixch I've already got an alpha done for onLoad. Would anybody like to see what's there so far?

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    i haven't got your point... What is that about, precisely?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #8
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    basically, there's a DOM way to register events (addEventListener()), there's an IE6+ way to register events (attachEvent()), and there's a pre-standards way to register events (element.onevent=handlerFunction).

    What I needed is a way to register several events to a single event, so I came up with an onLoadQueueManager script, made of a couple functions: addOnLoadHandler() and windowHasLoaded(). You can register any number events to run onLoad using the addOnLoadHandler() function, then the actual onLoad event triggers the windowHasLoaded(), which loops through the queue and executes each function.

    I'm in the process of turning this into a more generic event queue manager, eligible for any element and any event; basically turning it into an event management class with a -gasp!- fully documented API.

  • #9
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Seen Mike Foster's api?

  • #10
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Have a look at dithered by Chris Nott: <http://www.dithered.com/javascript/d...nts/index.html>
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #11
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hm. Just when I decide to undertake an arduous JavaScript journey, I find it's already been taken and conquered by others, actual pioneers. Damn this nasty habit I have of waiting until I *need* something to actually going and putting it together!

    Thanks for the links, cheese & liorean. These look like just what I was about to kill myself trying to build.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •