-3

I have this finction:

 var msec = 100;
   setInterval(function () {
            if (childNodeDocument.readyState == "complete") {
                parent.parent.mapFrame.hideModal;
                alert("complete");
                clearInterval();
            }
        }, msec);

when this condition is satisfied:

childNodeDocument.readyState == "complete"

I want to stop executing setInterval().

But the way I am doing above not working.

Any idea what I am missing?

Michael
  • 12,788
  • 49
  • 133
  • 253

2 Answers2

1

Store the id that is returned by setTimeout and use that to cancel it...

var msec = 100;
var intervalId = setInterval(function () {
        if (childNodeDocument.readyState == "complete") {
            parent.parent.mapFrame.hideModal;
            clearInterval(intervalId);
            alert("complete");
        }
    }, msec);

Also, note that I put it before your alert

freefaller
  • 18,589
  • 7
  • 54
  • 82
1
var interval = setInterval(function () {
//  ^^^^^^^^
    if (childNodeDocument.readyState == "complete") {
        parent.parent.mapFrame.hideModal;
        clearInterval(interval);
        //            ^^^^^^^^
        alert("complete");
    }
}, msec);
MazzCris
  • 1,802
  • 1
  • 13
  • 20