S
S
SergeyKisliy2014-09-02 20:30:41
JavaScript
SergeyKisliy, 2014-09-02 20:30:41

Correct inline display of the cookie entry. How to fix the error?

Hello! Unfortunately, I don’t understand JS, but I really need to make an editorial on the site, please help!
It is required to write the date in the cookie and then display part of it in html
Plugin for cookies - jquery.cookie.js

<script type="text/javascript">
            var d1 = [1,7,6,5,4,3,2];
            var today1 = new Date();
            var end1 = new Date(today1.getFullYear(),today1.getMonth(),today1.getDate()+ d1[today1.getDay()], 23, 59, 59);
 
            var now1 = new Date();
            var date = new Date();
            date.setTime(end1.getTime());
            date.setDate(date.getDate());
            bf=getMonth(end1);
            function getMonth(end1) {
                var month = ['января','ферваля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря'] ;
                return month[ end1.getMonth() ];
            }
            if($.cookie("timer")){
             var date = $.cookie("timer");
             }else{
              var date = new Date();
             date.setDate(date.getDate() + 14);
             bf=getMonth(date);
              $.cookie("timer", date, {expires: 14});
             }
        </script>

до <span><script  type="text/javascript">document.write(date.getDate() + " " + bf);</script></span>

At the first entry, everything is OK, and then date.getDate () is written in the console, not a function.
Moreover, if you completely display the date variable, then everything is OK, but only the day and month are required.
Help me please!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Senkevich, 2014-09-03
@ssenkevich

The error is that you are trying to get a Data object from a cookie, and only strings are stored in cookies. Those. you need to store the date in the cookie like this:
and get the date from the cookie like this:
date = new Date($.cookie("timer"));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question