SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to make this javascript keep going without restarting on page onload?

    Hi, I have some javascript that rotates items. Problem is
    as soon as you leave my web page and come back it starts over. Any way to keep it going all on its own so everything gets rotated?
    Here's the code with the problem under the [2] content. Its set to change every hour, but starts over as soon as you revisit the page. Please let me know how to fix this so it doesn't start over when you visit the page but keeps going. Thank you very much! Jennifer

    content[0] = "http://www.website.com/something.txt";
    content[1] = "http://www.website.com/something.txt";
    content[2] = "http://www.website.com/something.txt";

    var counter = 0;
    function secondsplus_iframe()
    { document.getElementById("dynstuff").src = content[counter];
    counter++; if (counter == content.length)
    counter = 0; } setInterval("secondsplus_iframe()", 3600000);

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    U would need to set a cookie and store the counter variable in it

  3. #3
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you saying that all javascript functions start over on page onload?

  4. #4
    SitePoint Addict bkennedy's Avatar
    Join Date
    Aug 2004
    Location
    michigan
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, javascript is client side, and html is stateless.
    That means the entire javascript "program" is on your visitor's machine and if their browser closes the js program (by navigating anywhere, even back to the same page) it starts all over.
    ----------------
    bob.kennedy
    ----------------


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
  •