mardi 22 mai 2018

wrong if statement evaluation, document.cookie

I`m trying to perform some action with document.cookie, I checking some If conditional mentioned below:

if((!document.cookie.indexOf('cookies:all_checked') >= 0) ||
   (!document.cookie.indexOf('cookies:first_and_second') != -1) ||
   (!document.cookie.indexOf('cookies:first_and_third') != -1) ||
   (!document.cookie.indexOf('cookies:first_only') != -1)){    
    createCookies();   
}

before this statement I create cookie like this

var variable = document.cookie == 'cookies:all_checked'

the trouble is no matter I`m trying do check

(!document.cookie.indexOf('cookies:all_checked') >= 0)

or the same without ! mark I get true with this condition. How to check is it cookies with this content is really setted?

Aucun commentaire:

Enregistrer un commentaire