Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   setTimeout not working on IE (http://www.velocityreviews.com/forums/t924222-settimeout-not-working-on-ie.html)

James Black 04-14-2006 05:27 PM

setTimeout not working on IE
 
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.


Lee 04-14-2006 05:57 PM

Re: setTimeout not working on IE
 
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>


--


Randy Webb 04-14-2006 06:37 PM

Re: setTimeout not working on IE
 
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/


All times are GMT. The time now is 08:16 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.