S
S
sanya1642015-01-09 03:56:46
JavaScript
sanya164, 2015-01-09 03:56:46

How to check for cookies and perform a specific action?

I have a code:
When entering the site, click appears, after clicking it, click is hidden and main appears

#main {
  display: none;
}

function FuncImages() {
  document.getElementById("main").style.display = "block";
  document.getElementById("click").style.display = "none";
}

<div id = "main">Данные</div>
<div id = "click" onclick = "FuncImages()">Здесь картинка</div>

How to make sure that if you click on click, cookies are entered, like:
document.cookie="click=yes;
And after reloading the page, it was checked whether cookies were entered. If they are, then you need to hide click and show main.
If not listed, then everything remains in its place

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Matvey Mamonov, 2015-01-11
@sanya164

PHP

if (isset($_COOKIE["name_of_cookie"])) {
  // то выполняем действия необходимые
}

A
Alex, 2015-01-09
@mr_ko

To work with cookies, I personally use the jQuery Cookie Plugin https://github.com/carhartl/jquery-cookie

if($.cookie('click')){
ваш код
}

N
Nikita Baev, 2015-01-09
@drugoi

You can do it like this → JSFiddle
(cookies do not work on jsfiddle, so test it yourself)

B
Bogdan, 2017-06-17
@lemonlimelike

Now in the SPA trend - single page application. So better ajax + optional VueJs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question