htmlanchor

How to hide an Anchor tag's href link in the HTML?


Trying to prevent web scrapers/crawlers from grabbing this URL that's located in an anchor tag. I don't want to hide the icon from the page itself, just from the HTML.

<a class="link" href="/hide_this_link_from_html"><img src="printIcon.jpg"/></a>


Solution

  • JavaScript.

    document.querySelector("a").addEventListener("click", function(event){
      var myURLOrPath = "/hide_this_link_from_html"
      event.preventDefault();
      alert("now use window.location.href to trigger navigate to " + myURLOrPath);
    });
    <a class="link" href="#"><img width=124px src="https://stackoverflow.design/assets/img/logos/so/logo-stackoverflow.png"/></a>