Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!