neicull
neicull

Reputation: 81

jQuery looping bug in iOS

Why would the difference between these two lines of code create a bug that cause jquery to loop endlessly in iOS(Safari and Chrome)? The loop did not occur in any other browser.

if ($('[name="loadingTime"]') != undefined) {...

vs

if ($('.loadingTime') != undefined) {...

When we targeted by class and not name attribute the loop bug went away. Any ideas or explanations?

Upvotes: 0

Views: 139

Answers (1)

neicull
neicull

Reputation: 81

Upon further investigation the bug was discovered in another part of the code. Here's what happened:

  loadInterval: function() {
  var settimer = $('[name="loadingTime]').val();
  var interval = setInterval(function() {
    if (settimer == 0) {
      window.clearInterval(interval);
      $('[id^="interstitial-container"]').remove();
    };
    settimer--;
    if (settimer >= 0) {
      $('.ncount').text(settimer);
    }
  }, 1000);
}

in

var settimer = $('[name="loadingTime]').val();

we missed a closing quote after loadingTime! which the js returned as undefined and iOS didn't handle it gracefully so var settimer wasn't set to zero so whenever that function loadInterval was called it was undefined and we checked whether we needed to load based on undefined or not. in our case it wasn't and continued to load over and over always getting an undefined response but without an error. I think...

Upvotes: 1

Related Questions