Skip to content Skip to sidebar Skip to footer

Show Pop Up Only Once Throughout One Navigation Of The Site

I have a website created using laravel. I want the user to be able to see a popup the first time he comes to my site. By first time I mean- the user comes to any page on my site(th

Solution 1:

you could use document.referrer, and check if the previous page is one of your domain. But not all visitors/browsers will return this value for security reasons.

So this is unreliable.

Solution 2:

Use a plugin like jQuery Cookie, then simply do:

if(!$.cookie("popup"))
{
 your_popup_function();
 $.cookie("popup",true);
}

Edit: since you edited your question regarding your definition of "first time visit", I'd advise the approach Walter Brand suggested, using the referrer. Taken from this post:

document.referrer.indexOf(location.protocol + "//" + location.host) === 0;

Solution 3:

Hi i did this solution while solving the client requirement "to show pop-up only once throughout navigating to different pages of the site" and it works good for me. I did it using cookie and setting the cookie value to the cookie creation time than i make the difference of the cookie value with current time using javascript setInterval function and compare the difference with the time on which i want to show the pop-up and it's work.

$(document).ready(function() 
{
var myVar=""; 

 functiongetCookie(name)
{
var re = newRegExp(name + "=([^;]+)");
var value = re.exec(document.cookie);
return (value != null) ? unescape(value[1]) : null;
}

functioncallagain()
          { 
            if(!getCookie("magazine"))
             {
              var c1= newDate();
              var c2=c1.getTime();
              document.cookie="magazine="+c2;
              }   
            var cvalue= getCookie("magazine");
            var cvalue2=parseInt(cvalue);
            myVar=setInterval(function(){ call22(cvalue2);},1000);     
       }

functioncall22(abcd)
{
var curdate = newDate();
var curtime = curdate.getTime();
var curtime2=parseInt(curtime);
var result=curtime2 - abcd;
if( (result >30000) && (result < 31000) )
             {
               alert(“POPUPONCETHROUGHOUTTHESITE”);
                clearInterval(myVar);
             }
}
callagain();                 
});

Post a Comment for "Show Pop Up Only Once Throughout One Navigation Of The Site"