Open Modal with Delay and After Closed No More

Asked

Viewed 47 times

0

I’m trying to create a modal bootstrap as a one-page greeting screen. The part of it open with delay I managed to do without problems, but I need that when the user closes it, it will not be shown again the next time that the same login on the screen. The modal code is the bootstrap standard and will contain only simple text.

$(window).on('load',function(){
    var delay = 1000;
    setTimeout(function(){
        $('#notificacao').modal('show');
    },delay);
});
  • The gnome worked out?

2 answers

1


localStorage - allows us to store data simply and without expiration, that is, they remain there until we erase by code or by the browser itself.

Syntax to save data to localStorage: localStorage.setItem("chave", "valor");

Syntax for reading localStorage data: var nomeVariavel = localStorage.getItem("chave");

Syntax to remove localStorage data: localStorage.removeItem("chave");

$(window).on('load',function(){
    var isshow = localStorage.getItem('isshow');
    if (isshow== null) {
        localStorage.setItem('isshow', 1);

        setTimeout(function() {
            $('#notificacao').modal('show');
        }, 1000);
    }
});

Suporte ao navegador

0

    $(window).on('load',function(){
    var delay = 1000;
    setTimeout(function(){
          // puxa o item no localstorege
        let janela= localStorage.getItem('janela');
        //verifico se e igual a null
        if(janela == null){
        $('#notificacao').modal('show');
        // seto o item no local storege para que ele n seja mais null
        localStorage.setItem('janela', 'true');
        }
    },delay);
});

Browser other questions tagged

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