1

I'm stuck because of timer issue.

Briefly, the code submits a form and the answer to the post is opened in an iFrame. An EventListener on the form allows me to detect the "submit" and apply a timer to detect if the iFrame loading is too long. But, even if the iFrame is loaded (=timer should be canceled), the timer's function is called. Here is the code :

[...]
var el = document.getElementById("myForm");
if(el){
el.addEventListener("submit", function(event){
    $scope.popupOpened=false;

    var iframeWindow = window.parent.document.getElementById('myIframe');
    var iframeDoc = iframeWindow.contentWindow.document;

    //7 seconds before the popup is shown up
    $rootScope.myTimer = $timeout(function(){
        window.frames[0].stop();
        if(!$scope.popupOpened){
        errorConnexion2();//popup opening
        }
    }, 7000);

    iframeWindow.onload=function(){
    console.log("iframe loaded");
        //cancel the timer
        $timeout.cancel($rootScope.myTimer);
   }
 });
}

[...]

I also tried with setTimeout and clearTimeout and by clearing all of them like that :Is there a way to clear all time outs?

What am I missing ? Thank you in advance !

Community
  • 1
  • 1

1 Answers1

0

Okay, so I found the reason why the timer wasn't canceled !

I tryied to debug, set alert() when the form was submitted and it figured out that the programm was entering multiple times in the submit eventListener. I though about catching all timers IDs and killing them but I finally decided to give up and find the root cause.

The issue was on my view, in the .html page I was calling multiple times 'ng-controller="MyCtrl"' ! So, I just deleted the extra ones and the program worked !

Hope it helps !