You can store this information in the Customer, whether through Cookies, localStorage, sessionStorage or Indexeddb.
Taking into account, that when storing in a cookie this information will traffic between the client and your server in each request, thus generating an additional traffic of information that will possibly not be used in the server, m of the question that a cookie has an expiration date, so I would say that Cookies are not a good idea for your scenario.
On the other hand, IndexedDB
provides you with a structure too large for this problem, it would be like killing an ant with a nuclear fusion bomb.
So you can use localStorage
or sessionStorage
, however sessionStorage will disappear once the tab or browser is closed, so if you want this information to remain until the end of time (or the user cleans Storage), you should choose localStorage.
recalling that the localStorage
a key and a value, both as string
, if you need to store an object, you should make use of the JSON.parse
and of JSON.stringify
.
var json = localStorage.getItem("dados de acesso");
var dados = {};
if (!json) {
dados = { primeiroAcesso: true };
} else {
dados = JSON.parse(json);
}
console.log(dados);
if (dados.primeiroAcesso) {
/* Abra o seu dialog */
dados.primeiroAcesso = false;
localStorage.setItem("dados de acesso", JSON.stringify(dados));
}
console.log(dados);
Like the Snippet
wheel sandbox
, cannot use localStorage in it, so the above example will not work, however you can open it in Jsfiddle
Thanks for the help, only now he doesn’t close the modal anymore, with this code
– Junior
Well, I can’t reproduce the problem to help you, try a little more and return here with some message.
– Vinicios Yals
i entered the site Jscookies, in my index I put the <Script src = "js.cookie.js"> </script> and put what you advised in ?
– Junior
I don’t know, I need to see your code more broadly to understand the problem.
– Vinicios Yals