Search code examples
jquerytoastr

Show toastr once after succesful login


I want to show only once toastr notification after the user has a successful login. If the user tried to reload the page or the user redirect to another page, I don't want to reshow the notification. Is that possible?


Solution

  • You can achieve that with local.storage():

    Window.localStorage

    var isLogged = localStorage.getItem("isLogged");
    
    if(!isLogged){
        alert('notification');
    }
    
    localStorage.setItem("isLogged", true);
    
    
    //on logout or window.onbeforeunload remove from local storage
    //localStorage.removeItem("isLogged");
    

    Example: localStorage example

    NOTE: to check stored items go to browser console under Application tab Local Storage section