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 Coder
    Join Date
    Dec 2010
    Posts
    22
    Thanks
    3
    Thanked 1 Time in 1 Post

    Div content change after 10 seconds?

    I want a code that changes text (of maybe a div) after 10 seconds.
    So like i could have some text and a link on my page then after 10 seconds it will change to something else and i can make it change to as many things as i want. Then when it goes threw them all it starts over.

    THANKS

  • #2
    Regular Coder
    Join Date
    Apr 2010
    Posts
    163
    Thanks
    3
    Thanked 25 Times in 25 Posts
    Code:
    <script type="text/javascript">
    var content=["<a href='www.url.com'> link 1 </a>",
                 "< a href='www.url2.com'> link 2 </a>",
                 "insert html content"]
    function change(){
               var new=foo.shift()
               document.getElementById('change').innerHTML=new;
               foo[foo.size-1]=new
    }
    setInterval(change, 10000);
    </script>
    
    <div id="change"> </change>

  • Users who have thanked gizmo1650 for this post:

    codelook (12-05-2010)

  • #3
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,145
    Thanks
    38
    Thanked 505 Times in 499 Posts

    Lightbulb Modified script ...

    I tweeked 'gizmo1650's script just a bit for testing purposes.
    Code:
    <script type="text/javascript">
    // From: http://www.codingforums.com/showthread.php?t=211050
    
    var content = [
      "<a href='www.url.com'> link 1 </a>",
      "<a href='www.url2.com'> link 2 </a>",
      "insert html content"
    ];
    var msgPtr = 0;
    var stopAction = null;
    
    function change() {
      var newMsg = content[msgPtr];
      document.getElementById('change').innerHTML = 'Message: '+msgPtr+'<p>'+newMsg;
      msgPtr++;  msgPtr = (msgPtr % content.length);
    }
    
    function startFunction() { change();  stopAction = setInterval(change, 5000); }
    function stopFunction() { clearInterval(stopAction); }
    
    </script>
    
    <button onclick="startFunction()">Start</button>
    <button onclick="stopFunction()">Stop</button>
    <div id="change" style="border:5px solid red;width:300px; height:200px;background-Color:yellow"> </div>
    He was on the right track, just needed some mods.

  • Users who have thanked jmrker for this post:

    codelook (12-05-2010)

  • #4
    New Coder
    Join Date
    Dec 2010
    Posts
    22
    Thanks
    3
    Thanked 1 Time in 1 Post

    Thumbs up Thanks

    This is great! it will do exactly what i want!!

  • #5
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,145
    Thanks
    38
    Thanked 505 Times in 499 Posts

    Arrow

    Quote Originally Posted by codelook View Post
    This is great! it will do exactly what i want!!
    You're most welcome.
    Happy to help, I'm sure, from both of us.
    Good Luck!

  • #6
    New Coder
    Join Date
    Dec 2010
    Posts
    22
    Thanks
    3
    Thanked 1 Time in 1 Post
    sorry but i couldn't get it to start automatically any help?

  • #7
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,145
    Thanks
    38
    Thanked 505 Times in 499 Posts

    Lightbulb

    Quote Originally Posted by codelook View Post
    sorry but i couldn't get it to start automatically any help?
    Code:
    ....
    onload = function() {
      startFunction(); 
    }
    </script>
    ....

  • #8
    New Coder
    Join Date
    Dec 2010
    Posts
    22
    Thanks
    3
    Thanked 1 Time in 1 Post
    thanks again

  • #9
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change background after 20 seconds or so

    Hi,
    is it possible to change the background color of a webpage from black to white after 20 seconds or so? Please help. Thanks

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,300
    Thanks
    203
    Thanked 2,561 Times in 2,539 Posts
    Quote Originally Posted by shunail View Post
    Hi,
    is it possible to change the background color of a webpage from black to white after 20 seconds or so? Please help. Thanks
    Yes, of course it is possible. But this is so simple that you ought to Google for the answer.
    And please do not revive some long-finished thread. Prefer to start a new thread of your own.

    Here you are:-

    Code:
    <script type = "text/javascript">
    
    document.bgColor = 'black';
    setTimeout(changeBGC, 20000);  // 20 seconds
    
    function changeBGC(){
    document.bgColor = 'white';
    }
    </script>
    "99.9 percent of lawyers give the rest a bad name." - Unknown
    Last edited by Philip M; 07-21-2012 at 09:12 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #11
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks SO MUCH Philip. I did searched Google but only thing I found was random colors scripts, named Disco Script. Thanks for the code


  •  

    Tags for this Thread

    Posting Permissions

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