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?