简体   繁体   中英

Browser tab Cookie Session

I have a website displaying popup ad for users who have visited the site first time, cookie is set as per the browser session. So, if user closes and opens the browser ad displays. But is it possible if the user leaves the browser open and closes all the opened tabs of that website and reopens the website again. Will the ad display, with out setting the time. Currently using browser session cookie code but I don't want the below code:

window.onload = function(){
    var popUp = document.cookie.indexOf('ad=');
    if(popUp < 0){          
      document.cookie = "ad=opened";
      ad.trigger();
    }       
  };

I have also configured timely session but I'm not looking for that.

multi-tab issue where, if the user closes all tab but keeps the browser open and then open a new tab with the site, ad should display. So this means even if they did not close the browser but just closed the tab and they revisit the website again while they haven't closed the browser, ad should show.

If I get it right, you are tying to show the user an ad whenever he´s getting to your page the first time. So why dont try it with document.referrer ?

I got a solution from this Post

I would try something like this:

if(document.referrer.indexOf(location.protocol + "//" + location.host) !== 0) {
    ad.trigger();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM