How to show popup only once through cookies

I want to show popup only once, and I have already written code for it but it is not working.

I want to execute did_you_know_slide_in() function only once.

Can anyone guide me what i am doing wrong.


function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length

      end = document.cookie.indexOf(";", offset);

      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function loadornot(){
    if (get_cookie('hasSeen')==''){
        document.cookie="hasSeen=yes"
        did_you_know_slide_in();
    }
}

loadornot();


Your code works so something else must be wrong.

Any console errors?

Are you sure you’re deleting all cookies for the domain?

A useful bookmarklet is javascript:alert(document.cookie);

Your cookie reader doesn’t check that the matched name is a whole word, so in a cookie string like peanuts=2;nuts=1 it would pick up the value of ‘peanuts’ when searching for ‘nuts’.

function get_cookie(Name)
{
 var cString;

 return ( ( cString = document.cookie.match( "(^|;|\\\\s)" + Name + "=([^;$]+)" ) ) ) ? decodeURIComponent( cString[ 2 ] ) : "";
}