We\'re creating a click tracking app, that builds heatmaps. I\'m writing a script which users are suppose to insert into their pages for tracking to work.
It works
The JavaScript is basically executed in single thread. It is not possible to have your callback function executed and at the same time have an infinite loop waiting for a flag variable from it. The infinite loop will occupy the single execution thread and the callback will never be called.
Best approach is to cancel the default handler of your event and bubbling for it (basically return false if you are really building your tracking code with jQuery), and do the necessary actions (redirect page to the necessary address if a link was clicked or trigger other default actions), but this would take a lot of careful work to recreate all the possible combinations of actiona and callbacks.
Another approach is to: 1) Look for something specific to your code in the event data 2) If it is not present - make an AJAX call and in its callback re-trigger the same even on the same element, but this time with your specific bit added to the even data; after the AJAX call return false 3) If your specific bits are present in the data - simply do nothing, allowing the default event processing to take place.
The either approach may bite, however.