Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

96
Visualizações
How do I show the last visit on my website with a cookie?

The basic idea is that every time somebody visits the website the cookie saves the time and date. If the user then visits the website multiple times the cookie only shows the date and time when the user last visited. At the moment I have the following code which does work put obviously always updates the date and time:

var today = new Date();
var date = today.getDate()+'-'+(today.getMonth()+1)+'-'+today.getFullYear();
var time = today.getHours()+':'+today.getMinutes()+':'+today.getSeconds();
var dateTime = date+' at '+time;
document.cookie ='last_visit='+ dateTime 

Edit:For other people who might need help, the following code seems to work:

var today = new Date();
var date = today.getDate()+'-'+(today.getMonth()+1)+'-'+today.getFullYear();
var time = today.getHours()+':'+today.getMinutes()+':'+today.getSeconds();
var dateTime = date+' at '+time;
function getCookieValue(a) {
    const b = document.cookie.match('(^|;)\\s*' + a + '\\s*=\\s*([^;]+)');
    return b ? b.pop() : '';
}
console.log ("getCookieValue " + getCookieValue("last_visit"));
document.cookie ='last_visit='+ dateTime
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You cannot share visited data between users on the cookies without receiving data from the server.

The solution is to save the last visit DateTime into the Database and send it back to the client

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda