SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Jquery set interval question

    Hello forums

    I have this code:

    Code HTML4Strict:
    <div id="mainChat" style="display:none">
    <div id="chatWindow"></div>
     
    <script type="text/javascript">
    setInterval("loadContent()", 1000 );
    </script>
     
    </div>

    loadContent() is a function to load an external file inside "chatWindow" div. I want it to run every 1 second.

    Question: does the setInterval function runs even if "mainChat" div is hidden?

    Thanks
    Don't Panic

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Yes, it does
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh jeez it does! I'll have to call the interval somewhere else. Thanks scallioXtX
    Don't Panic

  4. #4
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or you can use javascript to check if the div is hidden or not before calling and assigning the setInterval() to a variable

    Code:
     
    var timer = setInterval("loadContent()", 1000 );
    if the div subsequently becomes hidden/invisible then you can use clearInterval() to stop the setInterval from continuing


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
  •