Hello! Dear community, I ask again for your help, in the continuation of this topic I made such a crutch , it is strange that the modal window with the content does not appear, it may have got out of the scope of the frame, everything works locally. The question is how to make my window no longer appear if the user has a cookie. I can not figure out how to add if () {}

Here so, does not work:

<script type="text/javascript"> $(document).ready(function() { var getCookieValue = $.cookie("visit"); if (getCookieValue == true) { $("a.gallery2").fancybox( { "padding" : 20, "imageScale" : false, "zoomOpacity" : false, "zoomSpeedIn" : 1000, "zoomSpeedOut" : 1000, "zoomSpeedChange" : 1000, "frameWidth" : 700, "frameHeight" : 600, "overlayShow" : true, "overlayOpacity" : 0.8, "hideOnContentClick" :false, "centerOnScroll" : false }).click(); } }); </script> 

    2 answers 2

    We receive cookies from the user's machine

     $(function(){ var getCookieValue = $.cookie("visit"); alert("Пользовательская печенька: " + getCookieValue); }); 

    If you need to make the alert work only if getCookieValue not true then just wrap it in if . Something like this:

     if(getCookieValue != true) { alert("Пользовательская печенька: " + getCookieValue); } 
    • alert is just to check if the cookie is gone! I need for that piece of code that is responsible for displaying a modal window - Artyomich
    • so wrap it in the same if. Everything is similar. - KryDos
    • does not work!!! supplemented the question. Maybe I incorrectly wrapped ...? - Artyomich
    • That seems to be correct. And what exactly does not work? How this "does not work." Is it somehow manifested? - KryDos
    • I indicated an error in the title of the question) The firebug console displayed the message: Uncaught ReferenceError: getCookieValue is not defined - Artyomich

    Colleagues! Found a solution:

    It turns out that it is impossible to compare with the variable getCookieValue , since the variable is not global , but it is right to immediately read the cookie in the condition and compare it with the condition value.

    Here is the solution:

     $(document).ready(function() { $("a.gallery2").fancybox( { "padding" : 20, "imageScale" : false, "zoomOpacity" : false, "zoomSpeedIn" : 1000, "zoomSpeedOut" : 1000, "zoomSpeedChange" : 1000, "frameWidth" : 700, "frameHeight" : 600, "overlayShow" : true, "overlayOpacity" : 0.8, "hideOnContentClick" :false, "centerOnScroll" : false }); if ($.cookie("visit") == "true") { $("a.gallery2").fancybox().click(); } }); 

    And here's another solution:

     <script type="text/javascript"> $(document).ready(function() { // Создаем cookie "visit" var getCookieValue = $.cookie("visit"); // Проверяем если cookie value = true if (getCookieValue == "true") { return false } else { $("a.gallery2").trigger("click"); } $.cookie("visit:, "true", { expires: 1 }); // Устанавливаем время жизни cookie $("a.gallery2").fancybox({ // Код fancybox }); }); </script>