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 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Body onload alternative?

    Hi,

    Is there any alternative to the ' body onload="" ' function?

    I have on the page several scripts running and one is blocking the others because of the body onload function.

    It is working if I change that to body onfocus but it is loading the content all over when the user gets back to the page.

    Any ideas how can I avoid this?

    I can't apply onload to some element, onfocus is not working and this code also does not suite me:

    Code:
    <script type="text/javascript> 
    function(); 
    </script>
    Thanks in any case!

    Batric

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Code:
    <script type="text/javascript">
    
    function addListener(obj, evt, handler)
    {
       if (obj.addEventListener)
       {
          obj.addEventListener(evt, handler, false);
       }
       else if (obj.attachEvent)
       {
          obj.attachEvent('on' + evt, handler);
       }
    }
    
    function init()
    {
       doSomething();
       doSomethingElse();
       makeThatThree();
    }
    
    addListener(window, 'load', init);
    
    </script>
    Also, could add all three separately.
    btw it's window.onload, body tag or not.

  • Users who have thanked adios for this post:

    batric (05-20-2009)

  • #3
    New Coder
    Join Date
    Oct 2008
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Solved the issue - just added caller code to the bottom of the page (before closing body tag) and it works!

    Thanks a lot in any case

  • #4
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please forgive me for asking what is likely obvious to everyone with programming bona fides,... I am looking for the html counterpart to the code above that Adios generously shared, so that I can include the following code (minus the "body window.onload", of course) into my html page.

    <body window.onload="new Effect.Appear('one', { duration: 1.0, from: 0.0, to: 1.0, delay: 0.6 }); new Effect.Opacity('one', { queue: 'end', duration: 0.5, from: 1.0, to: 0.6, delay: 0.4 }); Effect.Appear('two', { duration: 1.0, from: 0.0, to: 1.0, delay: 1.4 }); new Effect.Opacity('two', { queue: 'end', duration: .5, from: 1.0, to: 0.6, delay: 0.4 }); Effect.Appear('three', { duration: 1.0, from: 0.0, to: 1.0, delay: 2.2 }); new Effect.Opacity('three', { queue: 'end', duration: 0.5, from: 1.0, to: 0.6, delay: 0.4 }); Effect.Appear('previous', { duration: 1.0, from: 0.0, to: 1.0, delay: 0.1 }); new Effect.Opacity('previous', { queue: 'end', duration: 0.5, from: 1.0, to: 0.4, delay: 0.1 }); Effect.Appear('next', { duration: 1.0, from: 0.0, to: 1.0, delay: 0 }); new Effect.Opacity('next', { queue: 'end', duration: 0.5, from: 1.0, to: 0.4, delay: 0 }); Effect.Appear('crown_logo', { duration: 1.0, from: 0.0, to: 0.8 }); return false;">

    My website is supposed to display the fade in effect (using script.aculo.us and prototype, which can be seen here). I have recently added a drop-down menu, as well, but the above html will not work with the "window.onload" event present. see here.

    Thanks and regards,
    Todd


  •  

    Posting Permissions

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