HTML5 Banner Ad Loops 3 times but resets after Exit click opens a new window. How can I stop this?

The banner ad should only loop 3 times. Clicking the banner opens an Exit URL in another tab. When you go back to the banner ad tab the ad has reset and starts playing again. I’d like it to stop after 3 plays no matter what.

I assume this is a javascript coding issue. I’m not a coder but can understand basic html. Any help would be great!

(function() {
  function onImagesLoaded(container, event) {
    var preloads = [];
    preloads.push.apply(preloads, container.getElementsByTagName("img"));
    preloads.push.apply(preloads, container.getElementsByTagName("lottie-player"));
    preloads.push.apply(preloads, container.getElementsByTagName("video"));
    var loaded = preloads.length;
    for (var i = 0; i < preloads.length; i++) {
      var tag = preloads[i].tagName.toLowerCase();
      if (tag === "lottie-player") {
        preloads[i].addEventListener("ready", function() {
          loaded--;
          if (loaded == 0) {
            event();
          }
        });
      } else if (tag === "video") {
        preloads[i].addEventListener('loadeddata', function() {
          loaded--;
          if (loaded == 0) {
            event();
          }
        }, false);
      } else if (tag === "img") {
        if (preloads[i].complete) {
          loaded--;
        } else {
          preloads[i].addEventListener("load", function() {
            loaded--;
            if (loaded == 0) {
              event();
            }
          });
        }
        if (loaded == 0) {
          event();
        }
      }
    }
  }

  onImagesLoaded(document.getElementById("b_13"), function() {
    var elements = document.getElementById("b_13").getElementsByClassName('js-bnfy');
    for (var i = 0; i < elements.length; i++) {
      elements[i].style.display = 'block';
    }

    var playCount = 0;
    var lastPlay = false;
    var animationInterval;
    var exitTimeouts = [];

    function clearExitTimeouts() {
      exitTimeouts.forEach(clearTimeout);
      exitTimeouts = [];
    }

    function handleVisibilityChange() {
      if (document.hidden) {
        clearInterval(animationInterval);
        clearExitTimeouts();
      } else {
        replayAnimations();
        animationInterval = setInterval(replayAnimations, 9000);
      }
    }

    document.addEventListener("visibilitychange", handleVisibilityChange);

    function handleExits() {
      var el_img_9535 = document.getElementById("img_9535");
      var el_img_11122 = document.getElementById("img_11122");
      var el_img_9529 = document.getElementById("img_9529");
      var el_img_11124 = document.getElementById("img_11124");
      var el_img_4533 = document.getElementById("img_4533");

      el_img_4533.className = "bnfy-enter";
      var timeout = setTimeout(function() {

        el_img_4533.className = '';
        void el_img_4533.offsetWidth;
        el_img_4533.className = "bnfy-exit";
      }, 3200);
      exitTimeouts.push(timeout);
      var el_img_9534 = document.getElementById("img_9534");

      el_img_9534.className = "bnfy-enter";
      var timeout = setTimeout(function() {

        el_img_9534.className = '';
        void el_img_9534.offsetWidth;
        el_img_9534.className = "bnfy-exit";
      }, 3200);
      exitTimeouts.push(timeout);
      var el_img_9533 = document.getElementById("img_9533");

      el_img_9533.className = "bnfy-enter";
      var timeout = setTimeout(function() {

        el_img_9533.className = '';
        void el_img_9533.offsetWidth;
        el_img_9533.className = "bnfy-exit";
      }, 3600);
      exitTimeouts.push(timeout);
      var el_img_4528 = document.getElementById("img_4528");
      var el_img_4526 = document.getElementById("img_4526");
      var el_img_13 = document.getElementById("img_13");
    }

    handleExits();
    var playbackLoop = animationInterval = setInterval(function() {
      playCount = playCount + 1;
      lastPlay = playCount === 2;
      replayAnimations();

      if (playCount === 2) {
        clearInterval(playbackLoop);
      }
    }, 9000);

    function replayAnimations() {
      var banner = document.getElementById("b_13");
      if (banner) {
        var elements = banner.children;
        for (var i = 0; i < elements.length; i++) {
          if (elements[i] && elements[i].tagName.toLowerCase() !== 'script' && elements[i].tagName.toLowerCase() !== 'style' && elements[i].tagName.toLowerCase() !== 'noscript') {
            var display = elements[i].style.display;
            elements[i].style.display = 'none';
            void elements[i].offsetWidth;
            elements[i].style.display = display;
          }
        }
      }

      handleExits();
    }
  });
  if (!Enabler.isInitialized()) {
    Enabler.addEventListener(
      studio.events.StudioEvent.INIT,
      enablerInitialized);
  } else {
    enablerInitialized();
  }

  function enablerInitialized() {
    if (!Enabler.isVisible()) {
      Enabler.addEventListener(
        studio.events.StudioEvent.VISIBLE,
        adVisible);
    } else {
      adVisible();
    }
  }

  function adVisible() {
    function bgExitHandler(e) {
      Enabler.exit('Background Exit');
    }
    document.getElementById('b_13').addEventListener('click', bgExitHandler, false);
  }
})();

I tried editing the playcount but that didn’t work. i think it may need to use localstorage to save the playcount but I’m not sure how?

you need to modify the playbackLoop interval to stop after 3 plays, and also reset the playCount when the user navigates away from the tab and comes back.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật