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

263
Visualizações
How to make a html code only display once a day?

I want to show a preview player but i am going to add a refresh code that refreshes the page in 5 minutes so they can only see the html code for 5 minutes so my question is how would i set it up to make a cookie so it will only show my HTML code one time PER day. If they refresh it will say "YOU USED YOUR PREVIEW FOR TODAY COME BACK TOMORROW" or something..... Here is what i have tried Any help is greatly Appreciated i can use HTML or PHP it dont matter to me which :)

    <head>
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
    </head>
    <body>
    <div id="dialog" title="Test dialog">
    MY HTML CODE HERE
    </div>
    </body>
    </script>
    $(document).ready(function() {
    
       // Make sure dialog is initially hidden:
       $('#dialog').dialog({autoOpen: false});
    
        // Check for the "whenToShowDialog" cookie, if not found then show the dialog and save the cookie.
        // The cookie will expire and every 2 days and the dialog will show again.
    
        if ($.cookie('whenToShowDialog') == null) {
    
            // Create expiring cookie, 1 days from now:
            $.cookie('whenToShowDialog', 'yes', { expires: 1, path: '/' });
    
            // Show dialog
            $('#dialog').dialog("open");        
        }
    
    });
    </script>
PREVIEW USED FOR TODAY COME baCK TOMORROW
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can set a cookie that expires at the end of the day when a user visits the site.

document.cookie = `visited=true; expires=${dateObjectForEndOfDay}`;

Then, when a client visits the page you can read the cookie and see if it is set. Expired cookies won't display, so if the last cookie has expired it will be as if the user had never visited the site. (The below code is pinched from w3Schools

function getCookie(cname) {
  let name = cname + "=";
  let decodedCookie = decodeURIComponent(document.cookie);
  let ca = decodedCookie.split(';');
  for(let i = 0; i <ca.length; i++) {
    let c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}

const siteWasVisited = getCookie('visited');
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