SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: setInterval

  1. #1
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    setInterval

    I read in a few places that setInterval and setTimeout don't work in IE, but I've used them in IE 6,7 and 8, so what am I missing here? Is this some special condition? I'm not surprised IE causes a problem - I just want to know when it occurs.

    It was suggested you have to quote and use brackets, such as setInterval("myFunc()",2000); but I tried it without and it still works - i.e. setInterval(myFunc,2000) works fine in IE 6, even. Oddly, I had trouble with this at one time and thought it was lack of quotes and brackets, but it now works all the time. Is it a bad idea to omit the quotes and brackets? Here's a jQuery script for simple font expansion that works fine in IE6. I'm just wondering where the problem might arise:
    Code:
    <script type="text/javascript">
       jQuery(function(){     
           var setint, cnt=0;
           var target = jQuery('div#garble p');
           var fontsize = parseFloat(target.css('font-size'));
           function boobaw(){jQuery('#garble p').css('font-size',(fontsize+=1) + 'px');if(++cnt>15) clearInterval(setint)} 
           jQuery('button#clikme').click(function(){setint=setInterval(boobaw,500)});
        });
    </script>
    <button id="clikme">clikme!</button>
    <div id="garble"><p>grow me, please</p></div>
    Last edited by cybervigilante; Feb 11, 2010 at 16:36. Reason: err

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,870
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    I have never come across any suggestion that setInterval doesn't work in any version of IE. All the code I have ever written using it has worked in every version of IE that I ever tested it in.

    setInterval(myFunc,2000) is preferable to setInterval("myFunc()",2000) because it saves the step of converting the string into a function.
    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
    Feb 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    I have never come across any suggestion that setInterval doesn't work in any version of IE. All the code I have ever written using it has worked in every version of IE that I ever tested it in.

    setInterval(myFunc,2000) is preferable to setInterval("myFunc()",2000) because it saves the step of converting the string into a function.
    Here's the link that mentions this - webreflection.blogspot.com/2007/06/simple-settimeout-setinterval-extra.html Maybe he has a different meaning.

    It works, but I didn't make it a live link since the system is killing any replies with a link until I have five posts


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
  •