Answer the question
In order to leave comments, you need to log in
Hide block after three impressions?
Good afternoon. Please help me to modernize the code a bit.
It is necessary that the block is shown three times and then hidden.
I'm using js-cookie
I can't figure out how to record the increment of a variable.
here is the js code
var cookieNum = 0;
$(function(){
if (Cookies.get('disable_banner') === undefined) {
setTimeout(function() {
$('.block1').show();
},2000)
}
alert(cookieNum)
if (cookieNum == 3) {
Cookies.set('disable_banner', 1, { expires: 365 });
}
})
Answer the question
In order to leave comments, you need to log in
Write a counter to the cookie and check, update:
var cookieCounter = Cookies.get('disable_banner');
if (cookieCounter && cookieCounter < 3) {
/* Показываем блок */
cookieCounter++;
Cookies.set('disable_banner', cookieCounter, { expires: 365 });
} else {
Cookies.set('disable_banner', 0, { expires: 365 });
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question