skip to Main Content

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>

2

Answers


  1. But the best way to prevent search engines from scanning your page is to create a robot.txt file on your site. see https://www.robotstxt.org/ for usage).

    Login or Signup to reply.
  2. 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>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search