Este es mi código js, creo que tengo un bucle en la solicitud xhr ya que sigue cargando incluso sin la función de cookies; Estoy tratando de mostrar el "TnC" si no hay ninguna cookie. Sin embargo, continúa repitiendo la solicitud si es un no.
Además, cuando hago clic en aceptar en el formulario de envío, se vuelve a cargar.
muchas gracias por la ayuda
//función de cookies:
function setCookie(cname, cvalue, exdays) { if(document.getElementById('agree').checked){ const d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); let expires = "expires="+d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1); if (c.indexOf(name) == 0) return c.substring(name.length,c.length); } return ""; }//cokkie en carga + XHR
function checkCookieOnLoad() { if(getCookie("clicklink") === "yes") { var elem = document.getElementById("tmx"); elem.parentNode.removeChild(elem); var video = document.createElement('video'); video.type = "video/mp4"; video.src = ".//vid1.mp4"; video.autoplay = true; video.muted = true; video.id = "vdd1" document.body.appendChild(video); video.addEventListener("timeupdate", function(){ // current time is given in seconds if(this.currentTime >= 4.8) { // pause the playback this.pause(); this.remove(); location.replace("https://test.com"); } }); return true; } else { const xhr = new XMLHttpRequest(); const contianer = document.getElementById('tmx'); xhr.onload = function() { if (this.status ===200){ contianer.innerHTML = xhr.responseText; } } xhr.open('get', 'tnc.html'); xhr.send(); } }