Let’s say I trigger an event when a submit button is clicked, isn’t there a race condition between sending that event and the browser to unload the current page in order to navigate to the new one? In other words, it could happen that the form is submitted and the new page loaded before the event is completely sent, so it gets lost?
Sorry in case I don’t see the forest for the trees here. It just seems like an obvious issue to me and I couldn’t find anything about it. I also couldn’t find any examples on how to code a button (or link) click listener, which would give me confidence. The examples are only about triggering the event itself.
Currently I see the following possibilities:
- In practice the probability is almost 0 that the event gets overtaken by the new page load, so nobody cares about it.
- It’s a real issue and my idea of sending events on form submits (or even link clicks) is bad in the first place (and instead I should send them when the new page is loaded, or so).
I would appreciate any hints on this. Thanks in advance,
Best answer by Yuanyuan ZhangView original