document.addEventListener("DOMContentLoaded", function(event) { var classname = document.getElementsByClassName("social-network-header"); for (var i = 0; i < classname.length; i++) { //click gauche classname[i].addEventListener('click', obfuscateFunction, false); //click droit classname[i].addEventListener('contextmenu', obfuscateFunction, false); } }); var obfuscateFunction = function(event) { var attribute = this.getAttribute("data-snh"); var target = '_blank'; if (this.getAttribute("data-target") !== null) { target = this.getAttribute("data-target"); } if(event.ctrlKey) { var newWindow = window.open(decodeURIComponent(window.atob(attribute)), target); newWindow.focus(); } else { window.open(decodeURIComponent(window.atob(attribute)), target); } };