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

143
Views
How can I use variables inside window before unload

I am trying to use variables defined inside my React function in the window.addEventListner('beforeunload') function however it seems that the variables are already gone at that point. I need to do this to logout the user by calling a function inside my middleware called leaveRoom and pass in the variables "code" and "name". This is what I have tried:

...
149 window.addEventListener("beforeunload", e => 
150 {
151   if(!joined) return;
152   e.preventDefault();
153   leaveRoom({ code: code, username: name });
154 });
...
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It is not the best way but you can define globals.

window.code = "code"
window.username = "Cem"

after that, you can access these variables from anywhere.

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!