Take the 2-minute tour ×

I'm using Firefox 16.0.2.
I'm using an onload eventlistener to call a script which increases the value of a variable.
I need to get the variable's value before I increase it. Safari and Chrome (Webkit) give the right result but Firefox always alerts "0"...

This is my Script:

var obj = {
    build: function() {
        var progressCount = 0; 
        var otherFunction = function(number) {
        var finalFunction = function() {
        var progress = function() {
                alert(progressCount);   //    !  very important line !
                if (progressCount == ARRAY.length) {
        for (var i = 0; i < ARRAY.length; i++)
        ARRAY[i].addEventListener("load", progress);

What else could I try? Thank you very much!

share|improve this question
I have a similar one in my project, with same approach, but it works. So can you post a more complete script? –  xiaoyi Nov 20 '12 at 17:38
Is all the code you provided in the global scope or is this within a function or something? –  Ian Nov 20 '12 at 17:40
I just added the object and the function that contain my script, thanks for pointing that out! –  basbebe Nov 20 '12 at 17:45
Can you link to an actual page showing the problem? –  Boris Zbarsky Nov 22 '12 at 8:00
It works when i just call progress; from within the loop so it seems to have something to do with the event listeners... –  basbebe Nov 26 '12 at 7:50

Your Answer



Browse other questions tagged or ask your own question.