Answers.Body: <p>Here's how I approach what I think you're trying to do. I have a global Notice setup, which includes a lightswitch field called <code>showNotice</code>, a heading called <code>noticeTitle</code> and a text field called <code>noticeText</code>.</p>
  <p>Note I only check for the existence of the cookie. I'm not interested in the value, which is what you seem to be doing here:
  <code>{% if checkCookieHeader != globalheaderinfo.headerInfo %}</code></p>
  <p>Some cleaned up code from one of my sites:</p>
  <pre><code>{# Only show the notice at all if it's turned on in the CP #}
  {% if notice.showNotice %}
  
  {# Header bar shows all the time but the View button within shows only when the cookie has been set - controlled via CSS #}
  &lt;div id=&quot;notice-headerbar&quot;&gt;
      &lt;a href=&quot;#&quot; id=&quot;notice-viewbutton&quot; class=&quot;{{ not getCookie('noticed') ? 'hidden' }}&quot;&gt;View&lt;/a&gt;
      &lt;h2&gt;{{ notice.noticeTitle }}&lt;/h2&gt;
  &lt;/div&gt;
  
  {# The notice itself is only shown if the cookie has NOT been set. Controlled by CSS #}
  &lt;div id=&quot;noticeholder&quot; style=&quot;display: {{ getCookie('noticed') ? 'none' : 'block' }}&quot;&gt;
      &lt;section id=&quot;noticetext&quot;&gt;
          &lt;a href=&quot;#&quot; id=&quot;closenotice&quot;&gt;&amp;times;&lt;/a&gt;                
          &lt;p&gt;{{ notice.popupNoticeText }}&lt;/p&gt;
      &lt;/section&gt;
  &lt;/div&gt;
  {% endif %}
  </code></pre>
  <p>If they hit the close button, I set the cookie using Javascript. There's also the option to show the notice again by clicking the View button.</p>
  <pre><code>$('#closenotice').click(function(e) { 
      $('#noticeholder').slideUp();
      Cookies.set('noticed', 'yes');
      e.preventDefault();
      $('#notice-openbutton').removeClass('hidden').fadeIn();           
  });
  $('#notice-viewbutton').click(function(e) { 
      $('#noticeholder').slideDown();
      e.preventDefault();
      $(this).fadeOut();
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-20T09:55:31.313Z
Answers.Text: Thank you Clive for your answer. It works now that when I change the entry via navigation, the info stays. But when I close it, it reappears on the next page. 
  
  {% if globalheaderinfo.showHeaderNotice %}
      <div class="header-info" id="noticeholder" style="display: {{ getCookie('noticed') ? 'none' : 'block' }}">
        {{ globalheaderinfo.headerInfo }}
      </div>
    {% endif %}
  
    $(document).ready(function() {
      $('#closenotice').click(function(e) { 
        $('#noticeholder').slideUp();
        Cookies.set('noticed', 'yes');
        e.preventDefault();          
      });
    })
Answers.UserDisplayName: ChuckLean
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-18T16:26:59.063Z
Answers.LastActivityDate: 2022-01-18T16:32:25.150Z
Answers.LastEditDate: 2022-01-18T16:32:25.150Z
Answers.UserDisplayName: Clive Portman
Body: <p>We want to solve a pop-up or a so-called &quot;header info&quot; about the cookie plugin &quot;Cookies&quot;. We have assigned and created the cookie accordingly. It appears as soon as we set (initial set) a cookie via globals or change the text of &quot;globalheaderinfo.headerInfo&quot;.</p>
  <p><strong>Actual state:</strong> The cookie appears as soon as it is set or the text is changed. But as soon as I switch from the Home e.g. to the Contact page (by clicking on Contact page in the navigation) the cookie disappears.</p>
  <p><strong>Target state:</strong> The cookie must not be closed until I have clicked on the Close button.</p>
  <p>Craft-Version: 3.7.28</p>
  <p>Cookies-Plugin-Version: 1.1.15</p>
  <p>Here our Code:</p>
  <pre><code>{% if getCookie('Header') %}
    {% set checkCookieHeader = getCookie('Header') %}
    {% if checkCookieHeader != globalheaderinfo.headerInfo %}
      &lt;div class=&quot;header-info&quot;&gt; 
        {{ globalheaderinfo.headerInfo }}
      &lt;/div&gt;
      {% do 'Header' | setCookie( globalheaderinfo.headerInfo, now | date_modify(&quot;+1 year&quot;).timestamp) %}  
    {% endif %}
  {% else %}
    {% set checkCookieHeader = getCookie('Header') %}
    &lt;div class=&quot;header-info&quot;&gt; 
      {{ globalheaderinfo.headerInfo }}
    &lt;/div&gt;
  {% do setCookie('Header', globalheaderinfo.headerInfo, now | date_modify(&quot;+1 year&quot;).timestamp) %}
  {% endif %}
  </code></pre>
  
Tags: <plugins><cookies>
Title: Cookie-Plugin: Why does Cookies get closing by change entry via navigation / menu?
ThreadText: # Cookie-Plugin: Why does Cookies get closing by change entry via navigation / menu?
  
  (Asked by: username_0 on 2022-01-18)
  
  We want to solve a pop-up or a so-called "header info" about the cookie plugin "Cookies". We have assigned and created the cookie accordingly. It appears as soon as we set (initial set) a cookie via globals or change the text of "globalheaderinfo.headerInfo".
  
  **Actual state:** The cookie appears as soon as it is set or the text is changed. But as soon as I switch from the Home e.g. to the Contact page (by clicking on Contact page in the navigation) the cookie disappears.
  
  **Target state:** The cookie must not be closed until I have clicked on the Close button.
  
  Craft-Version: 3.7.28
  
  Cookies-Plugin-Version: 1.1.15
  
  Here our Code:
  
  ```
  {% if getCookie('Header') %}
    {% set checkCookieHeader = getCookie('Header') %}
    {% if checkCookieHeader != globalheaderinfo.headerInfo %}
      <div class="header-info"> 
        {{ globalheaderinfo.headerInfo }}
      </div>
      {% do 'Header' | setCookie( globalheaderinfo.headerInfo, now | date_modify("+1 year").timestamp) %}  
    {% endif %}
  {% else %}
    {% set checkCookieHeader = getCookie('Header') %}
    <div class="header-info"> 
      {{ globalheaderinfo.headerInfo }}
    </div>
  {% do setCookie('Header', globalheaderinfo.headerInfo, now | date_modify("+1 year").timestamp) %}
  {% endif %}
  
  ```
  
  **Tags:** plugins, cookies
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-01-18. Score: 1 | Accepted answer
  
  Here's how I approach what I think you're trying to do. I have a global Notice setup, which includes a lightswitch field called `showNotice`, a heading called `noticeTitle` and a text field called `noticeText`.
  
  Note I only check for the existence of the cookie. I'm not interested in the value, which is what you seem to be doing here:
  `{% if checkCookieHeader != globalheaderinfo.headerInfo %}`
  
  Some cleaned up code from one of my sites:
  
  ```
  {# Only show the notice at all if it's turned on in the CP #}
  {% if notice.showNotice %}
  
  {# Header bar shows all the time but the View button within shows only when the cookie has been set - controlled via CSS #}
  <div id="notice-headerbar">
      <a href="#" id="notice-viewbutton" class="{{ not getCookie('noticed') ? 'hidden' }}">View</a>
      <h2>{{ notice.noticeTitle }}</h2>
  </div>
  
  {# The notice itself is only shown if the cookie has NOT been set. Controlled by CSS #}
  <div id="noticeholder" style="display: {{ getCookie('noticed') ? 'none' : 'block' }}">
      <section id="noticetext">
          <a href="#" id="closenotice">&times;</a>                
          <p>{{ notice.popupNoticeText }}</p>
      </section>
  </div>
  {% endif %}
  
  ```
  
  If they hit the close button, I set the cookie using Javascript. There's also the option to show the notice again by clicking the View button.
  
  ```
  $('#closenotice').click(function(e) { 
      $('#noticeholder').slideUp();
      Cookies.set('noticed', 'yes');
      e.preventDefault();
      $('#notice-openbutton').removeClass('hidden').fadeIn();           
  });
  $('#notice-viewbutton').click(function(e) { 
      $('#noticeholder').slideDown();
      e.preventDefault();
      $(this).fadeOut();
  });
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you username_1 for your answer. It works now that when I change the entry via navigation, the info stays. But when I close it, it reappears on the next page.   {% if globalheaderinfo.showHeaderNotice %}     <div class="header-info" id="noticeholder" style="display: {{ getCookie('noticed') ? 'none' : 'block' }}">       {{ globalheaderinfo.headerInfo }}     </div>   {% endif %}    $(document).ready(function() {     $('#closenotice').click(function(e) {        $('#noticeholder').slideUp();       Cookies.set('noticed', 'yes');       e.preventDefault();               });   })  
  
  ---
  
  