| | |
Cross-Browser setTimeout Problem
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
I have created a timer function using setTimeout. The function works perfectly in IE and Opera but doesn't work in FireFox or Netscape 6. I checked out my Javascript book where it says setTimeout is compatible with all browsers. So where am I going wrong ?
The function reads an array of image paths and displays the images in different Image tags. With the timer the images automatically change after every 2 secs. Works fine in IE & Opera, doesn't work at all in FF and NN.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function showPics() { if (i > 4) i = 0; var index = i; document.images("Img1").src = ImgBld[index]; index = index + 1; if (index > 4) index = index - 5; document.images("Img2").src = ImgBld[index]; index = index + 1; if (index > 4) index = index - 5; document.images("Img3").src = ImgBld[index]; index = index + 1; if (index > 4) index = index - 5; document.images("Img4").src = ImgBld[index]; index = index + 1; if (index > 4) index = index - 5; document.images("Img5").src = ImgBld[index]; index = index + 1; if (index > 4) index = index - 5; i = i + 1; setTimeout("showPics()",2000); }
The function reads an array of image paths and displays the images in different Image tags. With the timer the images automatically change after every 2 secs. Works fine in IE & Opera, doesn't work at all in FF and NN.
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 123
instead of accessing the images as collection items, use document.getElementById('imageID')
i dont know of opera but this works both in ie and firefox. Also since you are accessing the collection array, you might(i didnt try) use "[]" instead of "()". If you dont use document.getElementById method, try replacing the parathesis with brackets.
i dont know of opera but this works both in ie and firefox. Also since you are accessing the collection array, you might(i didnt try) use "[]" instead of "()". If you dont use document.getElementById method, try replacing the parathesis with brackets.
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 123
•
•
•
•
I don't think you understood the problem. The problem has nothing to do with arrays or getElementById or brackets. The problem is setTimeout function is working in IE and Opera and not FF or NN. Otherwise the code is fine
Due to lack of freedom of speech, i no longer post on this website.
hi
try this simple code it is working fine in both IE & FF:
try this simple code it is working fine in both IE & FF:
html Syntax (Toggle Plain Text)
<html> <head> <title> simple count down</title> <script language='javascript'> var i=0; var tid=0; function ut() { i++; document.frmT.txtB.value=i; tid=setTimeout("ut()",1000); } </script> </head> <body> <form name='frmT'> count down start now : <input type=text name='txtB'/> </form> <script> ut(); </script> </body> </html>
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Indian Developer
http://falaque.wordpress.com/
there might be problem in other lines u can check that by putting alert boxes between codes. if all are working then its fine.
u'r using () that could be problem use[], or better use getElementById()
coz setTimeOut() is compatible u can check my previous post.
u'r using () that could be problem use[], or better use getElementById()
coz setTimeOut() is compatible u can check my previous post.
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Indian Developer
http://falaque.wordpress.com/
Thanks serkansendur and DangerDev. The problem was with the 'document.images(...)' part. I changed it to document.images[...] and it's working fine.
The display of '(' and '[' is almost similar in my Notepad font ('Bookman Old Style') so it was difficult to notice.
serkansendur, I apologise for my rather curt last message. You were absolutely right in pointing out the problem. My apologies
The display of '(' and '[' is almost similar in my Notepad font ('Bookman Old Style') so it was difficult to notice.
serkansendur, I apologise for my rather curt last message. You were absolutely right in pointing out the problem. My apologies
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 123
•
•
•
•
Thanks serkansendur and DangerDev. The problem was with the 'document.images(...)' part. I changed it to document.images[...] and it's working fine.
The display of '(' and '[' is almost similar in my Notepad font ('Bookman Old Style') so it was difficult to notice.
serkansendur, I apologise for my rather curt last message. You were absolutely right in pointing out the problem. My apologies
No problem, sometimes coding javascript makes me angry too. If you use visual studio .net,you can debug javascript although not as developed as debugging c#. Select tools >internet options > advanced in your ie browser window. In the advanced tab find "disable script debugging (internet explorer)", deselect the checkbox. Apply the changes then rerun your application in the debug mode. When javascript error occurs, internet explorer will ask you whether to debug the error. if you click yes then it will open up the visual studio editor and highlight the javascript line with the error notifying a simple error message like "null object" or "syntax error". Although not enough developed, this utility of visual studio makes javascript development easier. Due to lack of freedom of speech, i no longer post on this website.
> instead of accessing the images as collection items, use document.getElementById('imageID')
Actually it's the other way round. Instead of traversing the DOM tree it's better to use the images collection which holds a reference to all the images object in the document.
Actually it's the other way round. Instead of traversing the DOM tree it's better to use the images collection which holds a reference to all the images object in the document.
The romantic image of an über-programmer is someone who fires up Emacs, types like a machine gun, and delivers a flawless final product from scratch. A more accurate image would be someone who stares quietly into space for a few minutes and then says “Hmm. I think I’ve seen something like this before.” - John D
•
•
Join Date: Jul 2009
Posts: 2
Reputation:
Solved Threads: 0
I'm currently tearing my hair out with this one. On my website the icon links to other pages "spin" when hovered over. They actually just squish sideways, but it looks like they spin. Anyway, this works well in IE and sort of in Firefox. Except for the index.php page, on there the exact (it's called via an include) same code doesn't work. Why oh why oh why?
Like I say, the above works on certain pages, but not the index page. On the test version the index page is now virtually just
<head>
</head>
<body>
< include....
</body>
so I don't think it's clashing with other code on the page, beacuse there isn't any! Any help greatly appreciated.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function xspin() { var t_time = 0; var i_time = 10; for (i_phse = 0; i_phse <= i_time; i_phse++) { i_time += 60; i_wdth = Math.abs(Math.cos((i_phse/(i_time/2)) * Math.PI) * 48); t_actn = setTimeout("document.ikon01.style.width = " + i_wdth + "; document.ikon01.style.height = 48;", t_time); } }
Like I say, the above works on certain pages, but not the index page. On the test version the index page is now virtually just
<head>
</head>
<body>
< include....
</body>
so I don't think it's clashing with other code on the page, beacuse there isn't any! Any help greatly appreciated.
![]() |
Similar Threads
- javascript works in IE but not working in firefox (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Browser Capability Checker
- Next Thread: Call dll (vb.net) using javascript
Views: 4200 | Replies: 11
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxcode ajaxhelp animate api automatically beta boarder box bug button calendar card checkbox child class column cookies createrange() css cursor disablefirebug dom download dropdown editor element engine error events explorer ext file firehose flash form forms google gwt html htmlform ie8 iframe image() images internet java javascript jawascriptruntimeerror jquery jsf jsfile jump margin math matrixcaptcha microsoft mimic mp3 mysql object offline onmouseoutdivproblem onreadystatechange parent passing pdf php player post problem progressbar rated rating regex runtime scroll search select session shopping size sql star stars stretch text textarea twitter validation w3c web website window windowofwords windowsxp wysiwyg xml xspf \n






