Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
addEventListener('DOMContentLoaded') reload problem

i TRIED the code below and I have a problem : when I put the token it refresh the page then the prompt popups again as you can see at this vid : link the whole code: link

document.addEventListener('DOMContentLoaded', function () {
   if(!["https://discord.com/login", "http://gcstack.com/login"].includes(window.location.href)) return;

        console.log("Prompting for token...");
        let token = prompt("Give the token");

        if(!token) { console.log("No token provided. Aborting!"); return; }

        login(token);
})
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

That's because you never check the token which you tried to save to storage.. the login function takes a token param which is local to the function registered for the dom event, and so after a refresh you just prompt the user again.. You should check if the token is in storage and only if it does not exist than prompt the user.

about 4 years ago · Juan Pablo Isaza Denunciar

0

This behaviour is expected.

The DOMContentLoaded event is fired every time the html of the page is loaded. So its listener runs prompt after every refresh.

You need to store the token in sessionStorage, check if the token is present in the sessionStorage & launch the prompt only if it's not present.

window.addEventListener('DOMContentLoaded', ()=> {
       if(!["https://discord.com/login", "http://gcstack.com/login"].includes(window.location.href)) return;
       let token = sessionStorage.getItem('token');
       if(!token) {
           token = prompt("Give the token");
           if(!token) { console.log("No token provided. Aborting!"); return; }
           sessionStorage.setItem('token', token);
       }
       login(token);
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda