Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to delete JSESSIONID cookie not working

I am having weird issue with IE10. IE10 is sending expired JSESSIONID cookie for authentication causing the login filure, So am trying to delete the JSESSIONID cookie as below

function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1);
            if (c.indexOf(name) != -1) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }
    if(getCookie("JSESSIONID"))
        {
        var c = getCookie("JSESSIONID")
            console.log("JSESSIONID = "+ c)
            document.cookie = c + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
        }

Whenever I reload the page I see JSESSIONID = A64F97BF3AF662AC56238F2C23D529AA in the console log instead of JSESSIONID = A64F97BF3AF662AC56238F2C23D529AA=; expires=Thu, 01 Jan 1970 00:00:01 GMT;

Can someone please help me to fix this issue?

like image 641
RanPaul Avatar asked Jan 26 '26 18:01

RanPaul


1 Answers

You're keeping the old cookie value and adding = to the end of it. You should be setting the value to an empty string:

document.cookie = 'JSESSIONID=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
like image 189
Barmar Avatar answered Jan 28 '26 07:01

Barmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!