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

321
Views
Can you differentiate between multiple variables using an addEventListener (javascript)?

Basically, I want to do something like this:

var a = 3;
var b = 4;
postMessage(a, '*');
postMessage(b, '*');

Then have a listener do something like this:

addEventListener('message', event => {
sessionStorage.setItem("variable a",event.data=a);
sessionStorage.setItem("variable b",event.data=b);

});

Evidently "event.data=a" and "event.data=b" are not real code, but I hope the meaning gets across...

Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If the types are the same, not really, with two addEventListeners - instead, consider posting an object composed of both a and b, and storing the stringified object in storage instead. This not only solves your problem, but it's also a much more manageable and elegant approach.

postMessage({ a, b }, '*');

and

addEventListener('message', event => {
  sessionStorage.setItem('datas', JSON.stringify(event.data));
});
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!