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

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

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 Report

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 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!