JQuery notification appears only once

0

How do I, according to the code below, only appear once per time?

<scriptsrc="assets/plugins/notification/js/bootstrap-growl.min.js"></script>
    <script>
    'use strict';
    $(window).on('load',function(){
      function notify(message, type){
          $.growl({
              message: message
          },{
              type: type,
              allow_dismiss: false,
              label: 'Cancel',
              className: 'btn-xs btn-warning',
              placement: {
                  from: 'top',
                  align: 'right'
              },
              spacing: 10,
              z_index: 999999,
              delay: 10000,
              animate: {
                      enter: 'animated fadeInRight',
                      exit: 'animated fadeOutRight'
              }
          });
      };
          notify('<span style="color: #000;font-size: 14px; font-weight: bold">ENVIAR MENSAGEM HOJE</span>&nbsp;<button type="button" class="close" data-growl="dismiss"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>', 'warning');
    });
    </script>
    
asked by anonymous 16.05.2018 / 20:12

1 answer

1

As the friend Guilherme Nascimento said in the comments, it is possible to use sessionStorage , recording a key, say "displayedMessage" and check if its value is "true" or something else, you choose ) before displaying the message. It would look something like this:

if(localStorage.getItem('exibiuMensagem') != true){
    notify(...);
    localStorage.setItem('exibiuMensagem', true);
}

So, with each access, if would check if this item already exists and has a value of 'true', otherwise it would display the message and save the item.

In addition, it is good to remove the item when the user closes the browser, so the next time the message appears again. You can do this with this function:

window.onbeforeunload = function{
   localStorage.removeItem('exibiuMensagem');
};
    
17.05.2018 / 14:56