JQuery Set Cookies Popup Setup One Day

Browser cookies popup accept, store cookies in browser with jQuery Cookies Html Markup code Thanks You.

Browser cookies popup accept, store cookies in browser with jQuery

JQuery Code
  //check to see if the submited cookie is set, if not check if the popup has been closed, if not then display the popup
  console.log('popupCookie',getCookie('popupCookie'));
  if( getCookie('popupCookie') !== 'closed'){ 
    $('.popup-overlay').css('display','flex');
  }
  $('a.close').click(function(){
    $('.popup-overlay').fadeOut();
  });

  // if click parent hide if click child not hide parent is .popup-overlay child is .popup
  $('.popup-overlay').click(function(e){
    if(e.target != this){
      return;
    }else{
      $('.popup-overlay').fadeOut();
    }
  });
  //setCookie( 'popupCookie', 'closed', 1 ); if click any link in popup
  $('.popupset a').click(function(){
    setCookie( 'popupCookie', 'closed', 1 );
    $('.popup-overlay').fadeOut();
  })	
function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
      var c = ca[i];
      while (c.charAt(0) == ' ') {
        c = c.substring(1);
      }
      if (c.indexOf(name) == 0) {
        return c.substring(name.length, c.length);
      }
    }
    return "";
  }

  function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    var expires = "expires=" + d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  }

Cookies Html Markup code

HTML Markup
<div class="popup-overlay">
  <div class="popup">
	  <a href="javascript:;" class="close"><i class="fa-solid fa-xmark"></i></a>
	  <h2>Cookies Title</h2>
	<div class="popupset">
    <p>Cookies Content</p>
    <a href="javascript:;" class="submit">Save Settings</a>
    </div>
  </div>
</div>

Thanks You.

Previous Code

How to copy a link on a clipboard WordPress?

How to share URL and copy to clipboard with URL ch ...

Next Code

Best Web Developer in Bangladesh: How to Find the Top Talent for Your Business

By: Toofan Developer Team Reading Time: 5 Minutes ...

Leave a Reply

Your email address will not be published. Required fields are marked *

If you find it useful

buymeacoffee

ACF

Blog

Elementor

HTML JQuery

PHP

WordPress

Change Jquery tab on next Prev button click

change active tab on button click javascript Ch ...

How to copy a link on a clipboard WordPress?

How to share URL and copy to clipboard with URL ch ...

top