Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

251
Visualizações
I want to hide a popup based on the client id and using html5 local storage

I'm quite new to all of these but here us my problem I have a popup that has a "don't show this again" checkbox. When a user checks this, local storage should save the client id (which is in the db) and the checked status of the checkbox. Based on these two factor the popup should be displayed or hidden

Here is my code:

$(document).ready(function () {

    $('#beforelight').css('display', 'block');

    $PopUp = $('#beforelight');

    var hide = JSON.parse(localStorage.getItem('hide'));
    var id = JSON.parse(localStorage.getItem('[[clientdb.id]]'));

    if (hide, id) {
        $PopUp.hide();
    } else {
        // initialize value in case it hasn't been set already
        localStorage.setItem('hide', false);
    }

    $('#checkbox').click(function () {
        $('#beforelight').hide();
        // toggle the boolean by negating its value
        var id = JSON.parse(localStorage.getItem('[[clientdb.id]]'));
        var hide = JSON.parse(localStorage.getItem('hide'));
        localStorage.setItem('hide', !hide);
    });
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Please try this code - JSON.parse is returns string

$(document).ready(function () {

    $('#beforelight').css('display', 'block');

    $PopUp = $('#beforelight');

    var hide = JSON.parse(localStorage.getItem('hide')) === 'true';
    var id = JSON.parse(localStorage.getItem('[[clientdb.id]]'));

    if (hide && id) {
        $PopUp.hide();
    } else {
        // initialize value in case it hasn't been set already
        localStorage.setItem('hide', 'false');
    }

    $('#checkbox').click(function () {
        $('#beforelight').hide();
        // toggle the boolean by negating its value
        var id = JSON.parse(localStorage.getItem('[[clientdb.id]]'));
        var hide = JSON.parse(localStorage.getItem('hide')) === 'true';
        localStorage.setItem('hide', !hide ? 'true' : 'false');
    });
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda