Joohansson/nanolinks

Hijacking of default link behavior

estelsmith opened this issue · 2 comments

The site is hijacking the default link behavior, forcing link clicks to open in the same tab even when using Cmd + Click to open the link in a new tab.

This only seems to happen in Google Chrome 75.0.3770.142 macOS but not Firefox 68.0.1 macOS.


Looking into the cause, it appears that click analytics is the culprit. Removing the event listener on links allows Cmd + Click to work again.

//Click analytics
$('a').click(function(e) {
//Only hitCallback when tracking links in same tab, to prevent speed button to use href (it uses new tab)
var params = {};
if (!$(this).hasClass("btn-external")) {
params.hitCallback = function () {
document.location = url;
}
}
if (!ga.q) {
var url = $(this).attr("href");
ga("send", "event", "outbound", "click", url, params);
e.preventDefault();
}
});

Good catch. It works with middle mouse button (in Windows with chrome and firefox) to open new tab and I guess I never tried with ctrl+click. The reason for the click analytics to be done in this "uncommon" way is because I have markdown links (that are converted to href in the markdown engine) and thus I can't use specific classes for links for the GA (which is how it's usually done). I will definitely look into this if it can be solved.

Verified working now in windows. Chrome and firefox. I will verify on Mac in a week.
Both middle mouse click and ctrl+click now opens new tab.