setTimeout not working on IE

Discussion in 'Javascript' started by James Black, Apr 14, 2006.

  1. James Black

    James Black Guest

    I am trying to fade a word out, so after 5 seconds then every 1/4 sec
    it should fade by a small amount, until it is gone.

    This works fine in Firefox, but IE never calls the function that
    setTimeout points to.

    I am using IE 6, btw, on WinXP SP2.

    browserdetect=savedspan.filters? "ie" : typeof
    savedspan.style.MozOpacity=="string"? "mozilla" : "";
    if (browserdetect=="mozilla") {
    savedspan.style.MozOpacity = 1.0;
    setTimeout(fadeSaved, 5000);
    } else if (browserdetect=="ie") {
    //alert("gradeSavedResult: inside the IE part");
    savedspan.filters.alpha.opacity = 1.0; // This should only be used
    in ie
    window.setTimeout("fadeSaved()", 5000);
    }


    function fadeSaved() {
    alert("fadeSaved: ");
    }

    I tried it with 'setTimeout(fadeSaved, 5000)' also, but that didn't
    work.

    Any idea why setTimeout wouldn't be working on IE?

    Thanx.
     
    James Black, Apr 14, 2006
    #1
    1. Advertising

  2. James Black

    Lee Guest

    James Black said:
    >
    >I am trying to fade a word out, so after 5 seconds then every 1/4 sec
    >it should fade by a small amount, until it is gone.
    >
    >This works fine in Firefox, but IE never calls the function that
    >setTimeout points to.
    >
    >I am using IE 6, btw, on WinXP SP2.
    >
    > browserdetect=savedspan.filters? "ie" : typeof
    >savedspan.style.MozOpacity=="string"? "mozilla" : "";
    > if (browserdetect=="mozilla") {
    > savedspan.style.MozOpacity = 1.0;
    > setTimeout(fadeSaved, 5000);
    > } else if (browserdetect=="ie") {
    > //alert("gradeSavedResult: inside the IE part");
    > savedspan.filters.alpha.opacity = 1.0; // This should only be used
    >in ie
    > window.setTimeout("fadeSaved()", 5000);
    > }
    >
    >
    > function fadeSaved() {
    > alert("fadeSaved: ");
    > }
    >
    > I tried it with 'setTimeout(fadeSaved, 5000)' also, but that didn't
    >work.
    >
    > Any idea why setTimeout wouldn't be working on IE?


    It should be easy enough to convince yourself that setTimeout()
    is working. It's probably your fadeSaved() function that doesn't
    work in IE.

    <html>
    <body>
    <script type="text/javascript">
    setTimeout("alert('setTimeout() works')",1000);
    </script>
    wait
    </body>
    </html>


    --
     
    Lee, Apr 14, 2006
    #2
    1. Advertising

  3. James Black

    Randy Webb Guest

    James Black said the following on 4/14/2006 1:27 PM:
    > I am trying to fade a word out, so after 5 seconds then every 1/4 sec
    > it should fade by a small amount, until it is gone.
    >
    > This works fine in Firefox, but IE never calls the function that
    > setTimeout points to.
    >
    > I am using IE 6, btw, on WinXP SP2.


    You shouldn't indent your code that much, it makes it a pain to do
    anything with when it gets wrapped.

    > browserdetect=savedspan.filters? "ie" : typeof
    > savedspan.style.MozOpacity=="string"? "mozilla" : "";


    Problem #1: Browser Detection
    <URL: http://jibbering.com/faq/#FAQ4_26 >

    If you want to use MozOpacity then test for it. If you want to use
    filters then test for them - not for something in a useless UA string.

    > if (browserdetect=="mozilla") {
    > savedspan.style.MozOpacity = 1.0;
    > setTimeout(fadeSaved, 5000);
    > } else if (browserdetect=="ie") {
    > //alert("gradeSavedResult: inside the IE part");
    > savedspan.filters.alpha.opacity = 1.0; // This should only be used
    > in ie
    > window.setTimeout("fadeSaved()", 5000);
    > }
    >
    >
    > function fadeSaved() {
    > alert("fadeSaved: ");
    > }
    >
    > I tried it with 'setTimeout(fadeSaved, 5000)' also, but that didn't
    > work.


    There may be something else in your code, that isn't posted, that is
    interfering with it. Post a small sample page that demonstrates
    setTimeout not working properly.

    var myTimer = window.setTimeout(myFunction,2000)
    function myFunction(){
    alert('Inside myFunction')
    }

    But, you might prefer setInterval over setTimeout and then have a
    counter that will clear the interval after enough time to finish the fade.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Apr 14, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RQ==?=

    javascript setTimeout does not work

    =?Utf-8?B?RQ==?=, May 2, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    8,816
    =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=
    May 2, 2006
  2. tshad
    Replies:
    4
    Views:
    172
    tshad
    Dec 3, 2004
  3. Athanasius

    setTimeout not working on Mac IE 5.2

    Athanasius, May 3, 2005, in forum: Javascript
    Replies:
    2
    Views:
    434
    Richard Cornford
    May 7, 2005
  4. SetTimeout not working

    , Aug 14, 2006, in forum: Javascript
    Replies:
    3
    Views:
    164
    Dr John Stockton
    Aug 14, 2006
  5. Shan

    SetTimeout not working with IE

    Shan, Feb 22, 2008, in forum: Javascript
    Replies:
    4
    Views:
    133
    Thomas 'PointedEars' Lahn
    Feb 24, 2008
Loading...

Share This Page