0

I have an pop-under. It opens a duplicate of current page and redirects old page to google.com. Also it is working once a day (with cookies). But every time it is blocking with popup blocker. I heard that I can avoid it with execution function on user interact so I added onscroll function:

document.addEventListener('scroll', function() {
function setCookie(cname,cvalue,exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires=" + d.toGMTString();
    document.cookie = cname+"="+cvalue+"; "+expires;
}

function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}

function showOnceInADay() {
    var user=getCookie("username1");
    if (user != "") {
    } else {
        window.open(window.location.href);window.location.href='https://www.google.com/';
           setCookie("username1", 1, 1);
    }
}


jQuery(document).ready(function($) {
        showOnceInADay() ;
});
})

How can I avoid it in another way? I've read answers to this question Avoid browser popup blockers but Can I do this without onclick event? Pop-under should be opened in first user interactive with a page

Stack1233
  • 85
  • 5
  • That's because the popup blockers in browsers are doing their job. No one wants a popup or popunder. Methods of creating such in Chromium-based browsers are reported as bugs (might be eligible for a bug bounty program, not sure). Why are you trying to create a popunder? – Samathingamajig Jun 27 '22 at 00:32
  • @Samathingamajig I'm trying to create popunder for ad purposes – Stack1233 Jun 27 '22 at 00:47

0 Answers0