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