Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!