Note: This is an asynchronous version of this question I asked yesterday: What happens when an event is triggered and page update both take place at the same time?
Given I have HTML like this:
<a id="google" href="http://google.com">Google.com</a>
And Javascript like this:
$('#google').on('click', function (event) {
event.preventDefault();
asyncFuncThatLogsAnalytics(this);
// Do some more
console.log("Click Click Bang Bang!");
window.location.href = $(this).attr('href');
});
When I click my Google
link, the click
event fires and the page immediately loads the next link…
What can I do to ensure all events within the click event have fired/finished BEFORE changing the window's location?