Home > Software design >  How to hide a publicity after user has realoded the page x times Laravel
How to hide a publicity after user has realoded the page x times Laravel

Time:05-17

On my website, on the index page, I have a bootstrap modal that shows publicities to the user when the page is loaded. I would like to hide this modal when the user would loaded the page more than 5 times, to not anoy the user.

Is there a way to do that? With session tricks?

Any sugestion? I don't find anything about this or I don't know how to find it.

Thank you!

CodePudding user response:

As @AkhzarJaved said, you can do this with JS localStorage.

let pubViews = parseInt(localStorage.getItem('pub_views')) || 0;
if (pubViews < 5) {
     document.querySelector('#publicities').style.display = 'block'; // or other display value
     localStorage.setItem('pub_views', (pubViews   1));
}
  • Related