How to use materialize Feature Discovery only on first page access?

Asked

Viewed 17 times

-1

Well, I have Feature Discovery in my js file that way:

  $(document).ready(function(){
     $('.tap-target').tapTarget();
     $('.tap-target').tapTarget('open');
   });
   function closeFeatureDiscovery() {
     $('.tap-target').tapTarget('close');
     $('.tap-target').tapTarget('destroy');
   }

It works normally but I would like it to open only the first time the person accesses the page and not every page that is accessed within the site. I did some searches and some recommend using Localstorage to store the status but I do not know if it is really the best solution for the case and also did not know how to search about this specific case.

  • 1

    There is no way to store this information that has already been opened once without using localStorage or a database.

1 answer

1


What’s the problem of using localStorage? You can use it, there is nothing abnormal or inelegant to do this. Another way would be using a cookie. Example of localStorage:

$(document).ready(function(){
   if (localStorage.getItem('discovered') == null ) { 
       $('.tap-target').tapTarget();
       $('.tap-target').tapTarget('open');
       localStorage.setItem('discovered', 1);
   };  
})
  • Cool Isaac! I adopted a solution very similar to this but using sessionStorage :D

Browser other questions tagged

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