SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I execute a JavaScript function on page load not after??

    Hello everyone, allow me to start off by saying you guys have a well disputed rep around the admin forums. This site comes very highly recommended and I see you guys have the content to back it up; super glad I joined. So now to the java stuff...

    I have been trying to work my way around this issue for some time now. I am trying to stop a marquee from scrolling as soon as the page start to load not after. I have been using this to pause the marquee with JavaScript but the command does not execute but after the page loads; after all the html loads.

    This is the JavaScript:

    Code:
    <script language="JavaScript">
      window.onload=function(){
            myMarquee.stop();
        }
       function function1(){
            document.all.myMarquee.direction = "left";
        }
        function function2(){
            document.all.myMarquee.direction = "right";    
        }
        function function3(){
            document.all.myMarquee.stop();
        }
          function function4(){
            document.all.myMarquee.start();             
        }
    </script>
    This is what I insert in my template:


    Code:
    <marquee id="myMarquee" BEHAVIOR=ALTERNATE>&nbsp;{vb:raw film_seriti}a></marquee>
    <img src="http://aniworlds.net/members/equinox/albums/random-renders/1874-left.png" onclick="function1();">
    <img src="http://aniworlds.net/members/equinox/albums/random-renders/1877-stop.png" onclick="function3();">
    <img src="http://aniworlds.net/members/equinox/albums/random-renders/1876-start.png" onclick="function4();">
    <img src="http://aniworlds.net/members/equinox/albums/random-renders/1875-right.png" onclick="function2();">
    With this code the marquee does stop but after the page loads completely so as the page loads the marquee start to scroll and then stops as soon as the page finishes loading but with the first image of the marquee have way out. I need to be able to load the marquee 100% stopped as the page loads so then I can use the buttons I placed to control the marquee.

    My question is:

    Is there ANY way to completely stop the marquee from scrolling as soon as the page loads???

    Any information anyone could share would be very much appreciated. Thank you for your time.

    p.s: Also if anyone has any idea on how to scroll the marquee by click; meaning by every click of the mouse the marquee moves either left or right, would be even better.
    p.s: Noted that this code does NOT work in FF for some reason. The stop does not work and the buttons don't respond. Any ideas why in FF they don't work but in GC and IE they do??

    Best Regards,

    Gustavo P.
    <snip/>
    Last edited by Mittineague; Jun 23, 2011 at 16:59. Reason: Please wait until you get your signature for your links.

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Get rid of the proprietary marquee tag and rreplace it with a marquee script witten in JavaScript. That way the marquee will not start moving until the script that makes it move runs. Also it will then work in all browsers and not just in Internet Explorer.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    Get rid of the proprietary marquee tag and rreplace it with a marquee script witten in JavaScript. That way the marquee will not start moving until the script that makes it move runs. Also it will then work in all browsers and not just in Internet Explorer.
    Thank you so much for the rapid reply. Question though, I'm using {vb:raw film_seriti} to call the marquee contents; will this also be parsed within a JavaScript marquee? If so, of the top of your head do you know of any good JavaScript resources out there? Googleing as we speak but just wanted to know if you know of any you have had experience with. Thank you again for your feedback.

    NOTE: I found some script that can work but there is only one problem, my content of the marquee is dynamic and as most script are in array I'm having a tough time finding the right one. If I could I would code it myself, learning daily though slowly but surely.


Bookmarks

Posting Permissions

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