Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

242
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda