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

142
Visualizações
Page keeps on loading on XML request on JS, after cookies check

I am new to JS so any help would be appreciated. I have created an XML request upon the page loading a video to check for cookies, and then replace a div element "tmx" with an external HTML file from my website. However the page keeps on reloading after fetching the XML request after injecting it to "#tmx". Another thing that I noticed is when I press accept tnc button on my document without the checkbox being ticked, the whole page is being completely reloaded. I think it might be the return value that might be wrong.

 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 "";
 }

 function checkCookieOnLoad() {
 if(getCookie("clicklink") === "yes") {
 


   var elem = document.getElementById("tmx");
                elem.parentNode.removeChild(elem);

                // var elem2 = document.getElementById("ooo");
                // elem2.parentNode.removeChild(elem2);


            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://www.test.com/index.html");
                                }

            });

   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();
 
 
   }
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

setTimeout(function() {
  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 "";
  }

  function checkCookieOnLoad() {
    if (getCookie("clicklink") === "yes") {



      var elem = document.getElementById("tmx");
      elem.parentNode.removeChild(elem);

      // var elem2 = document.getElementById("ooo");
      // elem2.parentNode.removeChild(elem2);


      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://www.test.com/index.html");
        }

      });

      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();


    }
  }
}, 5000);
/*This code will run after 5 seconds after the loading of HTML CSS and your JS files. Try it. Hope it helps you!!*/ 

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