-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
  • 13,950
  • 57
  • 145
  • 288

2 Answers2

2

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
  • 19,368
  • 7
  • 57
  • 87
1
var interval = setInterval(function () {
//  ^^^^^^^^
    if (childNodeDocument.readyState == "complete") {
        parent.parent.mapFrame.hideModal;
        clearInterval(interval);
        //            ^^^^^^^^
        alert("complete");
    }
}, msec);
MazzCris
  • 1,812
  • 1
  • 14
  • 20