SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    -
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript - Delay Code Please!

    Does anyone know how to delay launching a javascript file from a site? I need simple code to have a .js file launched after 45 seconds of someone visiting my site.

    Thanks,
    Josh

  2. #2
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    setTimeout('yourFunction()',45000)"

    ...should do the trick.
    It can go anywhere between the head tags...

    <script type&#61;"text/javascript">

    setTimeout...

    </script>


    or in the opening body tag...

    <body onload&#61;"setTimeout&#40;'yourFunction()'45000)">

    Just be sure that you have the page correctly linked (preferably in the head) to the external js file.

    <script src="yourjavascriptfile.js" type="text/javascript"></script>

    Hope this helps
    Last edited by Bill Posters; May 13, 2002 at 17:03.
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  3. #3
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    -
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I make "yourFunction" call up the script.js file? I'm just a beginner with javascript, and don't know too much.

    Thanks

  4. #4
    SitePoint Evangelist
    Join Date
    Jan 2002
    Posts
    420
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in your script.js make everything one big function

    then call it like above
    Wavelan

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats not the best way tho as the page not may not have loaded. I dont have time to explain as i'm about to take my maths exam, so i will give you some code to work on

    PHP Code:
    function checkLOAD()
    {
      if (
    document.body.complete && document.images.complete)
      {
        
    document.write ('your flash movie')
        
    clearInterval
      
    }
    }

    setInterval('checkLOAD',1000); 


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
  •