Opening a JavaScript-based link in a new window/tab.
I have a link
<a href='/page' onclick='trackClick()'>Page</a>
What I believe is happening here is that the trackClick() function may not have enough time to execute before browser redirects to a new page. (BTW: Am I wrong here?)
To workaround that, I have changed the html to
<a href='#' onclick='trackClick('/page')'>Page</a>
where trackClick function would redirect to a next page after it has sent a signal to analytics endpoint to avoid racing condition.
As a result, "shift+click" or "right+click open in a new window" now will not open the the /page in a new window/tab.
What's the best way to overcome this? How likely for the browser to not wait for the onclick event to finish before redirecting to a next page?
thank you