2014-06-24 1 views
0

쿠키가 있는지 확인하려고합니다. 그렇지 않으면 기초를 발사하여 모달을 발합니다. 모달에있는 버튼을 클릭하면 다음에 페이지가로드 될 때 모달이로드되지 않도록 새 쿠키가 설정됩니다.연령 확인을위한 쿠키가 있는지 확인하십시오.

쿠키를 설정했지만 쿠키가 브라우저 기록에있는 경우에도 내 모달 상자가 나타나기 때문에 내 확인이 작동하지 않는 것 같습니다.

$(document).ready(function() { 

    if ($.cookie('ageVerification') == undefined || $.cookie('ageVerification') == null || $.cookie('ageVerification') != 'Verification that user is over the legal drinking age in your country') { 

     // Reveal modal 
     $("#myModal").reveal(); 

     // Set Cookie on click 
     var ageVerification = document.getElementById('ageVerification'); 

     ageVerification.addEventListener('click', function (event) { 
      $.cookie('ageVerification', 'Verification that user is over the legal drinking age in there country', { 
       expires: 10, //expires in 10 days 

       path: '/', //The value of the path attribute of the cookie 
       //(default: path of page that created the cookie). 

       domain: 'becketts.knibbshost.co.uk', //The value of the domain attribute of the cookie 
       //(default: domain of page that created the cookie). 

       secure: true //If set to true the secure attribute of the cookie 
       //will be set and the cookie transmission will 
       //require a secure protocol (defaults to false). 
      }); 
      $('#myModal').hideModal() 
     }); 
    } 
}); 
+0

쿠키가 실제로 첫 번째 위치에 설정되어 있지 않습니다. http://becketts.knibbshost.co.uk – Turnip

+1

쿠키 검사에서 마지막 "or"문을 꺼내십시오. 작동하면 문자열 비교에 누락 된 부분이 있습니다 (아마도 마침표). – StaticVoid

답변

0

내 쿠키 세트의 추가 설정이 작동하지 않는 문제를 수정했습니다.

대답은 실행하려면 다음 스크립트를 필요 :

$(document).ready(function() { 

if ($.cookie('ageVerification') == undefined || $.cookie('ageVerification') == null) { 

    // Reveal modal 
    $("#myModal").reveal(); 

    // Set Cookie on click 
    var ageVerificationBtn = document.getElementById('ageVerification'); 

    ageVerificationBtn.addEventListener('click', function (event) { 
     $.cookie('ageVerification', 'Verification that user is over the legal drinking age in there country', { 
      expires: 10, //expires in 10 days 
     }); 
     $('#myModal').hideModal() 
    }); 
} 

});

관련 문제