2012-08-07 3 views
0

모달 대화 상자에 쿠키를 추가하고 싶습니다만 어떻게해야할지 모르겠습니다. 24 시간 동안 쿠키를 추가하고 싶습니다. 아무도 도와 줄 수 있습니까? 자체가 잘 보이는jquery 모달 대화 상자에서 쿠키를 설정하는 방법

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script> 
<script type="text/javascript" href="/jquery/jquery.cookies.js"></script> 

<script> 
$(function() { 
     // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore! 
     if ($.cookie('showDialog') == undefined || $.cookie('showDialog') == null || $.cookie('showDialog') != 'false') { 

     $("#dialog:ui-dialog").dialog("disable"); 
     $(".selector").dialog({ hide: "slide" }); 
     $("#dialog-modal").dialog({ 
      width:860, 
      height: 420, 
      modal: true, 
      resizable:false, 
      draggable:false 
     }); 
     $.cookie('showDialog', 'false', { expires: 1 }); // set the cookie, with expiry after 1 day 
} 
    }); 

    </script> 



<link href="http://xxx.com/jquery/jquery.ui.all.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 

<div id="dialog-modal" title="Like Us on Facebook"> 
    <div class="fb-like-box" data-href="http://www.facebook.com/xxx" data-width="820" data-height="335" data-show-faces="true" data-stream="false" data-header="false"></div> 
</div> 
+1

귀하의 코드가 잘 보이는 :

<script type="text/javascript" href="/scripts/jquery.cookies.js"></script> 

당신은 또한 당신이 대화 상자를 표시 한 후 쿠키를 설정해야합니다. jQuery 쿠키 스크립트를 포함 시켰습니까? https://github.com/carhartl/jquery-cookie/ –

답변

2

귀하의 코드가 jQuery를 표준 일부가 아닌하지만 당신은 또한 jQuery를 cookies pluginscript 참조를 포함해야한다 : 여기에 모달 대화 내 코드입니다.

if ($.cookie('showDialog') == undefined || $.cookie('showDialog') == null || $.cookie('showDialog') != 'false') { 
    // show dialog... 
    $.cookie('showDialog', 'false', { expires: 1 }); // set the cookie, with expiry after 1 day 
} 
+0

대단히 감사합니다! – androider

+0

문제가 있습니다. 이제 창은 모달 대화 상자가 아니지만 내 페이지의 머리글 위에 있습니다 ... 위 질문에 편집 된 코드가 있습니다! 도움을 주셔서 감사합니다. Rory McCrossan – androider

관련 문제