-1

I have added some code to my website but just can't fiqure out how to add cookie functionality This is the code so far:

<script type="text/javascript">
$(document).ready(function () {
    $.fancybox('<p class="msgAlert">The following pictures contain nudity. <br />If you are not allowed or willing to watch such content please leave this page.<p><a href="javascript:void(0);" id="do_accept" class="button butgreen">Yes I Accept</a></p></p>', {
        closeBtn: false,
        closeClick: false,
        helpers: {
            overlay: {
                css: {
                    'background': 'rgba(0, 0, 0, 0.9)'
                }
            }
        }
    });
    $("body").on("click", "#do_accept", function () {

        $.fancybox.close();
    });
    $("body").on("click", ".fancybox-overlay", function () {
        window.location.href = "index.php";
    });

});
</script>

I can't add php code so I need some advice. The idea ist to have a 10 day cookie in order to show the message just once every 10 days. Here's the link: https://www.olafernst.com/photo/gallerynudes.html Thanks a lot

jcubic
  • 61,973
  • 54
  • 229
  • 402

1 Answers1

0

To set cookies in javascript just use document.cookie

document.cookie = "Name=Value; expires=<DATE>';

to get date in right format you can use toUTCString method on Date object.

To add days to current date you can use answer to this quetion: How to add number of days to today's date?

You use jquery so you can use jQuery cookie plugin for this as @gustavogb write in a comment.

Community
  • 1
  • 1
jcubic
  • 61,973
  • 54
  • 229
  • 402