Quiero mostrar un reproductor de vista previa, pero voy a agregar un código de actualización que actualice la página en 5 minutos para que solo puedan ver el código html durante 5 minutos, así que mi pregunta es cómo lo configuraría para hacer una cookie para que solo mostrará mi código HTML una vez POR día. Si se actualizan, dirá "USTED UTILIZÓ SU VISTA PREVIA PARA HOY VUELVA MAÑANA" o algo así... Esto es lo que he intentado. Cualquier ayuda es muy apreciada. Puedo usar HTML o PHP, no me importa cuál :)
<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 TOMORROWPuede configurar una cookie que caduque al final del día cuando un usuario visita el sitio.
document.cookie = `visited=true; expires=${dateObjectForEndOfDay}`;Luego, cuando un cliente visita la página, puede leer la cookie y ver si está configurada. Las cookies caducadas no se mostrarán, por lo que si la última cookie ha caducado, será como si el usuario nunca hubiera visitado el sitio. (El siguiente código se extrae de 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');