Javascript kodları şu şekilde aynı ilettiğiniz örnekteki gibi çalışır;



var ilkPopupURL = "http://example.com/first-ad";
var ikinciPopupURL = "http://example.com/second-ad";

var reklamListesi = [ilkPopupURL, ikinciPopupURL];

var reklamBeklemeSuresi = 60;

function setCookieForAd(name, value, seconds) {
    var expires = new Date();
    expires.setTime(expires.getTime() + (seconds * 1000));
    document.cookie = name + "=" + value + ";expires=" + expires.toGMTString() + ";path=/";
}

function getCookieForAd(name) {
    var keyValue = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
    return keyValue ? keyValue[2] : null;
}

function openPopupAd(url) {
    var height = 200; 
    var width = 300;
    var top = window.innerHeight - height;
    var left = window.innerWidth - width;
    var popup = window.open(url, '', 'height=' + height + ', width=' + width + ', top=' + top + ', left=' + left);
    return popup;
}

function initAd() {
    document.addEventListener('click', checkForAdDisplay);
}

function checkForAdDisplay() {
    reklamListesi.forEach(function(url, index) {
        if (!getCookieForAd('adShown' + index)) {
            openPopupAd(url);
            setCookieForAd('adShown' + index, 'true', reklamBeklemeSuresi);
        }
    });
}

initAd();