Put the if inside your event listener:
document.addEventListener("contextmenu", function(e){ if (e.target.name !== "Link") { e.preventDefault(); } }, false);
So basically it says: when the target element does not have a Link name, right-click.
source share