:::: 개발 ::::/::: A S P :::

클릭 한것 체크 쿠키에 저장하기

nayha 2014. 12. 10. 10:41
반응형

<script src="/abn/include/js/jquery-1.7.1.js"></script>

<script type="text/javascript">

          $(document).ready(function(){

 

               $("ul#ulOne li").click(function(){

                    //console.log($('li').index(this));  //return index,index start from zero(0)

                                                    

                                                     //클릭한 배너에 쿠키가 없으면 전체 카운트

                                                     if( getCookie('cookPop_'+$(this).attr('id')) ){

                                                                console.log("쿠키명 같음");

                                                     }else{

                                                                console.log("쿠키명 셋팅");

                                                                setCookie('cookPop_'+$(this).attr('id'), $(this).attr('id'), 365);

                                                     }

                                                     //console.log( $("span.abnPop").html());

                                                     $("span.abnPop").html( getCookie('cookPop_'+$(this).attr('id')) );

 

               });

          });

 

                     function setCookie(name, value, days) {

 

                                          if (days) {

                                                                var date = new Date();

                                                                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));

                                                                var expires = "; expires=" + date.toGMTString();

                                          } else {

                                                        var expires = "";

                                          }

                                          document.cookie = name + "=" + value + expires + "; path=/";

                     }

                    

                     function getCookie(name) {

                                          var i, x, y, ARRcookies = document.cookie.split(";");

                                          for (i = 0; i < ARRcookies.length; i++) {

                                                                x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));

                                                                y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);

                                                                x = x.replace(/^\s+|\s+$/g, "");

                                                                if (x == name) {

                                                                                     return unescape(y);

                                                                }

                     }

 

 

</script>

반응형