I have already searched and found nothing related, wanted a code to show a DIV on the second pageview of a person on a site, and not show more in a predetermined period.
I have already searched and found nothing related, wanted a code to show a DIV on the second pageview of a person on a site, and not show more in a predetermined period.
You can create a cookie with the current date and then search for this cookie. In the second preview, add another variable to the cookie to see what has already been seen.
For example:
// gerar um timestamp em milisegundos
var agora = Date.now(); // ou "new Date().getTime();" em browsers antigos
// ler a data do cookie, se houver
var dataCookie = document.cookie.match(/_criado=([\d]+)/);
dataCookie = dataCookie ? parseInt(dataCookie[0], 10) : agora;
// procurar no cookie por "_criado"
if (document.cookie.indexOf('_criado' == -1)){
// primeira visita: criar o cookie
document.cookie = document.cookie + '; _criado=' + agora + ';';
}
else if (document.cookie.indexOf('_segundavisita' == -1) && dataCookie + 2629740000 - agora > 0){
// segunda visita e caso o cookie esteja dentro de 1 mês de validade
document.cookie = document.cookie + ' _segundavisita=true;';
// corre aqui o código da segunda visita
}
Note: 2629740000
is 1 month in milliseconds