Cookie重新加载

时间:2017-06-23 17:09:51

标签: javascript php cookies

当我设置cookie时,它会在页面重新加载后消失。这是代码:

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
            <link rel="stylesheet" type="text/css" href="mainx.css">
        <script 
    src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
    </script>
        <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-
    cookie/1.4.1/jquery.cookie.min.js"></script>

    </head>
    <body>
    <style type="text/css">
        body {margin: 0;}
    .dropdown-notification {
        height: 30px;
       line-height: 40px;
       position: relative;
       top: -50px;
       transition: top .8s;
        text-align: center;
         background:  #FF9900;
        color: white;
    }
    .dropdown-notification.active {
       top: 0;
    }
    </style>

      <div class="dropdown-notification text-center">
          Cookies ensure the proper functioning of this site. By using it, you accept the use of cookies. <button class="close">Got it!</button> 
       </div>
       <script type="text/javascript">
// Check if cookie 



};
    if ($.cookie("noti") !== "closed") {
       $('.dropdown-notification').addClass('active');
    }


    // On button click close and add cookie (expires in 100 days)
    $('.close').on('click', function(){
       $.cookie("noti", "closed", { expires : 1000 });
       document.cookie = "username=Player; expires=Thu, 18 Dec 3019 12:00:00 UTC";
        $('.dropdown-notification').removeClass('active');
    })

    $('.delete-cookie').on('click', function(){
            var R_U_sure = prompt("Are You Sure? if yes, type 'YES'. if not type 'NO'");
        if (R_U_sure = "YES"){
            $.cookie("noti", "open");
            $('.dropdown-notification').addClass('active');
        }
        else{
             console.log('cookie cleared.');

        }
    })

       </script>

            <button class="delete-cookie">Reset Progress?</button>
    <DIV ID="main">
        <div id="navigationbar"></div>
            <div id="player">
                <audio controls autoplay hidden>
                <source src="FB1.mp3" type="audio/mpeg">
                    If you're reading this, audio isn't supported. :(
                </audio>
            </div>


        <li>
            <button class=""></button>
            <button class=""></button>
            <button class=""></button>
            <button class=""></button>
        </li>
    </DIV>



    </body>

    </html>

重置进度不起作用。它应该是YES或NO。但是当我点击它时没有任何反应。 有什么方法我可以在下次有人访问网站时保留cookie吗? 也许PHP cookie? 页面重新加载后,用户名cookie和关闭的cookie将消失。我希望页面识别用户,并且只在第一次显示cookie noti。其他问题是重置进度,在顶部提到。

0 个答案:

没有答案