How to open two popups one at a time when updating the tab?

0

I want to use two popup ads on my site, how do I open them one at a time when I refresh the page, I tried, but opens two pop-ups at the same time annoying any visitor, I tried the following script. >

(function () {
var isOpened = false;

var siteUrl  = "http://popup1";
var siteUrl  = "http://popup2";

document.addEventListener("click", function(){
    if (!isOpened) {
        isOpened = !!window.open(siteUrl, "_blank");
    }
  });
})();
    
asked by anonymous 19.07.2017 / 19:43

1 answer

0

Sorry for the comment, but using setInterval , an auxiliary variable and a method is simple. Here is an example:

var openedAds = 0;
var AdsToOpen = ['http://popup1','http://popup1'];
var interval;

var interval = setInterval(function(){
    window.open(AdsToOpen[openedAds], "_blank");
    openedAds += 1;
    if(openedAds === AdsToOpen.length){
        clearInterval(interval);
    }
}, 2000); 
AdsToOpen is the site you want to open. 2000 at the end of the code is the time between one popup and another (in ms)

    
19.07.2017 / 20:39