I'm appending a string to the HREF for outgoing links on my site, it works like this. I need to append it on click because although I wrote it as a string here, it's generated at the time of click so I can't just append it to all the links before any clicking happens:
//middle-click
$(document).on("mousedown", function (e1) {
$(document).one("mouseup", function (e2) {
if (e1.which == 2 && e1.target == e2.target) {
var e3 = $.event.fix(e2);
e3.type = "middleclick";
$(e2.target).trigger(e3)
}
});
});
$('a[href*="link.php"]').on('click middleclick', function(e) {
let link = this.getAttribute('href');
e.preventDefault();
window.open(`${link}`+`&appended=1`);
});
So this works for clicks and clicks with middle mouse button BUT what about users who right-click and open in a new window/tab? How do I detect this in jquery?