As far as I understand, you are trying to intercept the link click event, send some analytics data, and then recreate the click to continue navigation. So for this:
function NewTab(url) { var newTab = window.open(url,"_blank"); newTab.focus(); } $("a").on("click", function(e) {
First I create a new tab function that I can use if the user clicked the link to the link. Then I intercept the click, and if the Control key was pressed, I send the analytics and open the link in a new tab. Otherwise, I submit the analytics and then redirect the current tab. Backups still exist if the callback fails.
As a footnote, the easiest way to recreate the natural click of a link is $(this).click();
Hope this helps!
-v.p
source share