6
I set up a banner, where I need that when the user enters the site and clicks on the GOT IT button it disappears and when the user re-enters the site or loads another link no longer appears. Disappear I managed, but record the user with cookie not, I found an example (below) but did not understand the implementation!!!
Note: Remembering that never expires
COOKIE
// Create a cookie
$.cookie('the_cookie', 'the_value');
// Create expiring cookie, 7 days from then:
$.cookie('the_cookie', 'the_value', { expires: 7 });
// Read a cookie
$.cookie('the_cookie'); // => 'the_value'
$.cookie('not_existing'); // => null
// EDIT
// Attaching to a button click (jQuery 1.7+) and set cookie
$("#idOfYourButton").on("click", function () {
$.cookie('the_cookie', 'the_value', { expires: 7 });
});
// Attaching to a button click (jQuery < 1.7) and set cookie
$("#idOfYourButton").click(function () {
$.cookie('the_cookie', 'the_value', { expires: 7 });
});
HTML
<div class="gotit">
<div>
<p>We use cookies in order to improve your browsing experience on sugarcane.org, not to collect personal information. By continuing to use the site, you agree that it is OK. <a href="https://sugarcane.org/privacy-policy">Read about our privacy policy.</a></p>
<a href="#" title="GOT IT">GOT IT</a>
</div>
</div>
JAVASCRIPT
<script>
$(document).ready(function(){
$(".gotit A").click(function(){
$(".gotit").fadeToggle("slow");
});
});
</script>
Do you want a cookie with an expiration date? If so, how long?
– Sam
jQuery Cookie plugin is not missing?
– user60252
@Leocaracciolo I believe so, but load plugin for something so simple that can be done in pure JS I find unnecessary :D
– Sam