Article ayant servi de source à ce billet: Comment faire de l’obfuscation de liens pour votre maillage interne ? et version PDF – 410-gone.fr-Comment faire de lobfuscation de liens pour votre maillage interne.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
// Source/doc: https://www.410-gone.fr/seo/optimisation-on-site/maillage-interne/cocon-semantique/obfuscation.html // HTML pour les liens à obfusquer (les URLs doivent être encodées en base-64): // <span class="qcd" data-qcd="aHR0cHM6Ly93d3cuNDEwLWdvbmUuZnIvYS1wcm9wb3MuaHRtbA=="> // mentions légales // </span> // Encodage en base-64 en PHP: // https://www.php.net/manual/en/function.base64-encode.php document.addEventListener("DOMContentLoaded", function(event) { var classname = document.getElementsByClassName("qcd"); for (var i = 0; i < classname.length; i++) { //click gauche classname[i].addEventListener('click', myFunction, false); //click droit classname[i].addEventListener('contextmenu', myRightFunction, false); } }); //fonction du click gauche var myFunction = function(event) { var attribute = this.getAttribute("data-qcd"); if(event.ctrlKey) { var newWindow = window.open(decodeURIComponent(window.atob(attribute)), '_blank'); newWindow.focus(); } else { document.location.href= decodeURIComponent(window.atob(attribute)); } }; //fonction du click droit var myRightFunction = function(event) { var attribute = this.getAttribute("data-qcd"); if(event.ctrlKey) { var newWindow = window.open(decodeURIComponent(window.atob(attribute)), '_blank'); newWindow.focus(); } else { window.open(decodeURIComponent(window.atob(attribute)),'_blank'); } } |