Storage session

Hi,

I have a javascript code for session storage for a modal pop up done according to Bootstrap 4 documentation, but I guess I am missing something, because it is not working
<script>
	   $(document).ready(function() {
	    $(function() {
         if (typeof Storage != "undefined") {
              if (!localStorage.getItem("done")) {
    
                   setTimeout(function(){
                     $('#exModal1').modal('show');
                     }, 2000);
                     setTimeout(function() {
                      $('#exModal1').modal('hide');
                        }, 20000);
    localStorage.setItem("done", true);
  }
  }
});             
  }); 
 
</script>

Open in new window

Manuel-Remus StancaAsked:
Who is Participating?
 
Leonidas DosasCommented:
You better use sessionStorage:
	   $(document).ready(function() {          
	    $(function() {        
          
         if (typeof Storage != "undefined") {
              if (!sessionStorage.getItem("done")) {    
                   setTimeout(function(){
                    //Modal show
                     setTimeout(function() {
                     //Modal hide
                        }, 20000);
                     }, 2000);
                     
      sessionStorage.setItem("done", true);
  }
  }
          
});             
  }); 

Open in new window

0
 
Manuel-Remus StancaAuthor Commented:
Works!
It was a little bit tricky to me, but I managed to implement it!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.