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

245
Visualizações
Javascript - Check if Session Cookie still valid

We have a 'logged in' cookie which is set when signing into a clients CMS (via asp.net). Dependant whether the user has asked the site to 'remember me' or not the cookie will either have an expiry time/date set or just be a session cookie.

I need to provide an idle time message on the site via a JS script.

After 5 mins inactivity the script needs to check if the cookie is still active or not.

The inactivity check part of the script works fine - but there doesnt seem to be any way (I can find at least) to check a cookies expiry time / date / type via JS - so i'm not sure how to apprach the cookie check element. I wondered whether anywone was aware of a method to check whether the cookie is session or dated? Or Active? I noticed that the cookie itself is removed when expired on windows/ chrome - but retained despite expired on mac? so not sure a simple read check for the cookie name would be foolproof cross-device.

heres my code so far -

 var idleTime = 0;
    $(document).ready(function () {
        var idleInterval = setInterval(timerIncrement, 60000); 
        $(this).mousemove(function (e) {
            idleTime = 0;
        });
        $(this).keypress(function (e) {
            idleTime = 0;
        });
    });

    function timerIncrement() {
        idleTime = idleTime + 1;
        if (idleTime > 4) { 
            triggerAlertSortCookie();
        }
    }
    function triggerAlertSortCookie() {
      //Check if AALogin cookie has expired  - show message if so & refresh page.
    }

Any advice / suggested code apprach would be great. thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To clarify that I understand what you wanna do: you want to check if the cookie is valid at this moment. If that's correct, the best way is to implement simple request on server-side that will return boolean response or maybe 200 ok / 401 unauthorized status code.

Also, you can just return 401 unauthorized status code for any request made with not valid cookies, and in js you can refresh, redirect to login page, etc.

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