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!
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));
});