Recently, I came across a post on a coding forum discussing how to hide links from Google using JavaScript. The idea is to mask the URLs from being crawled by Google while still making them accessible to users. In my case, I have external URLs that I want my clients to be able to click on, but I don't want Google to index them.
Here is the code I have been working with:
<template>
<span href="https://www.example.com/" @click="linkAction($event)">
Link to Example Website
</span>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
@Component
export default class MainContent extends Vue {
linkAction(e:any): any {
window.location = this.encodeURL(e.target.getAttribute('href'));
}
encodeURL(s: any): any {
return (s || this)
.split('')
.map(function(_: any) {
if (!_.match(/[A-za-z]/)) {
return _;
}
const c = Math.floor(_.charCodeAt(0) / 97);
const k = (_.toLowerCase().charCodeAt(0) - 83) % 26 || 26;
return String.fromCharCode(k + (c === 0 ? 64 : 96));
})
.join('');
}
}
</script>
However, even after implementing this code, I can still see the original hrefs in the inspection tools, leading me to believe that Google is still indexing them. I would appreciate assistance on how to effectively achieve my goal of hiding these links from Google's crawl.