Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

please help to find problem in FF with javascript

Status
Not open for further replies.

butoremontas

Programmer
Mar 6, 2010
4
LT
Hello,
i have this (look below), in IE "alert(this.src + counttuna);" loops good - from 1 to 8, but in FF or Chrome "alert(this.src + counttuna);" loops from 8 to 0 in , i can't find why.
My english isn't so good, so if need more explanation, i will do.
Thanks for any help.

function getImageUrl() {
var counttuna=0;
for (i = 1; i <= 8; i++)
{
var imgsrc = folder+file+(i)+'.gif';
var img = new Image();

img.onerror = function (evt) {


//alert(this.src + " can't be loaded.");
}
img.onload = function (evt) {
counttuna++

alert(this.src + counttuna);
}
if(img.src != imgsrc) { // don't get stuck in an endless loop
img.src = imgsrc;

}
}
if(i=8)
{
//loadsnowimagescount(counttuna);
alert(counttuna)}}
 
Thanks for answer,
but i found more problems in this script.
I made some changes and now i found, that then i remove alert(counttuna) from the end of script and enable my function - loadsnowimagescount(counttuna) it not working. But then i put
.... if(i=8)
{alert(counttuna);
loadsnowimagescount(counttuna);
}}
script work good. I don't understand what alert(counttuna) doing to my script :).

Very interesting that FF looping this part var imgsrc = folder+file+(i)+'.gif'; from 8 to 0, and that makes errors.

I made my script smaller and now it is exactly what i need:

function getImageUrl() {
var counttuna=0;
for (i = 1; i <= 8; i++)
{
var img = new Image();
var imgsrc = folder+file+(i)+'.gif';
img.onload = function () {
++counttuna;
}

//img.onerror = function (evt) {
//}

if(img.src != imgsrc) { img.src = imgsrc;}}
if(i==8)
{loadsnowimagescount(counttuna);}}


Sorry but if(i==8) not work.
 
Sorry but if(i==8) not work.

Well, 'not working' depends on what you are trying to do with the original line in question.

If you are trying to set i to 8, then your original code was correct. If you are testing to see if i is equal to 8, then your original code is wrong, and my suggestion is correct. This is regardless of whether or not it solves your original problem.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Hello BillyRayPreachersSon ,
thanks for answer.
Everything is very simple - i want to get function loadsnowimagescount(counttuna), then will reach 8.
But this script don't count ++counttuna and i don't know why.
I get 0 in FF and good number in IE. This number depends on loaded IMG, that link not broken, this link test function img.onload = function ().
Again i want to remember, that on testing this script i found that IE counting good from 1 to 8, but in FF, IMG files in var imgsrc = folder+file+i)+'.gif';, (i) goes from 8 to 1, and that is impossible, but true. The function is - for (i = 1; i <= 8; i++) !!! i never saw any errors on scripting with this function before.
Heeeeeeelp :)

Andrius
 
Hello for all,
i solved this problem by changing {loadsnowimagescount(counttuna);}} into {setTimeout("loadsnowimagescount(counttuna);",100)}}
Why it start worked i don't know, it seems like i'm going to infinity :).
But i think it some kind of FF bug. Or netscape spree.

So solved!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top