V
V
Vladislav2021-06-11 16:01:18
JavaScript
Vladislav, 2021-06-11 16:01:18

How to check for a cookie in pure JavaScript?

Please tell me how to check the presence of a cookie in pure JavaScript

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladislav, 2021-06-11
@SlavaMaxwell

Thanks everyone, this helped

if (document.cookie.indexOf("nameCookie") == 0) {
    console.log('Куки есть');
    
}else{
    console.log('Куки нет');
}

S
Sergey, 2021-06-11
@gangstarcj

Why didn't the first link from Google work? https://learn.javascript.ru/cookies

L
Lynn "Coffee Man", 2021-06-11
@Lynn

Look in document.cookie .
But if the cookie is set with the HTTP-Only flag, then nothing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question