I need to attach an asynchronous behavior on the click event of a button. I want to let the browser open the new tab with the link first, and when I return on the previous page, then the async action is executed.
At first, I tested this: window.setTimeout(() => action(), 0);
It works fine in Chrome, but in Firefox action()
is executed before the link opens. Very bad. I can't believe that Firefox manages it like it's a synchronous block ?
So I tried window.setTimeout(() => action(), 1);
Now it works!
Does 1 millisecond make a difference here, or is there an explanation in the inner event loop ?
Do you know the answer ? (And why it is managed differently between Chrome and Firefox ?)