V
V
Vadim Efremov2017-05-13 12:00:29
JavaScript
Vadim Efremov, 2017-05-13 12:00:29

Opening and closing blocks with remembering cookies (cookies)?

TELL ME How to do it?
Initially there is a hidden div block

<div class="col" id="box1" style="display: none">
содержимое 
</div>

How to make that when you click on the link - div appeared and signed up for cookies for a certain time For example 7 days, and after that time it disappeared again
<a id="url1" href="#" >ССЫЛКА</a>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Krasin, 2017-05-13
@Mo45

JS function that will add CookieName with value value to cookies :

<script>
function setCookie(){
   days=7;
   myDate = new Date();
   myDate.setTime(myDate.getTime()+(days*24*60*60*1000));
   document.cookie = 'CookieName=value; expires=' + myDate.toGMTString();
}
</script>

Link:
<a id="url1" href="#" onclick='setCookie()'>ССЫЛКА</a>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question