How to use Session to prevent a modal from opening again?

Asked

Viewed 143 times

2

I have a website in HTML, in the index I put a modal to open as soon as the person enters, this modal is to collect the email of the person, however every time the person updates the site the modal again appears. I wonder if there is something to do using javascript where it opens only once, then appear again only if the user closes the browser and back.

1 answer

3


Has yes you can use sessionStorage;

The logic would be as follows, before the modal open you question:

 // É diferente de true?  <- nunca abriu?
if(!sessionStorage.getItem("abriu")){
   // Abra a modal
   sessionStorage.setItem("abriu",true); // na próxima vez ela não entrara na condição.
}
  • Gbrigado Gabriel, then within the if I would put the function responsible for April the modal?

  • @Sérgiomachado this !

  • It worked perfectly, thank you very much Gabriel Hugs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.