javascript - 如何使用哈希来屏蔽外部 URL 不被抓取?

标签 javascript vue.js vuejs2 nuxt.js

我一直在看这篇文章:Hide links from Google via JavaScript 。我想实现相同的目标:屏蔽网址以防止谷歌抓取,但就我而言,我有外部网址。我希望当我的客户点击这些网址时,他们可以使用这些网址,但谷歌不能抓取这些网址。

这是我到目前为止所拥有的:

<template>
 <span href="https://www.w3schools.com/" @click="linkAction($event)">
      Link to W3Schools
 </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.rot13(e.target.getAttribute('href'));
  }

  rot13(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>

当我检查它时,我仍然看到href,并且我认为谷歌仍然会抓取这些内容并将其编入索引。希望获得有关如何实现这一目标的一些帮助。

最佳答案

通过 <a href> 以外的元素导航使用会导致挫败感。当您中键单击某个链接时,您希望它在新选项卡中打开,但对于不在页面上的链接则不然。

如果您确实想躲避机器人,请使用以下内容:

  1. 定义链接元素 <a hidden-href="xxx" href="#">.......</a>
  2. 添加mouseover的监听器& focus (也可能触摸)
  3. 交互时填写 hrefhidden-href .

可以选择清理上行链路。这可能是不需要的,因为爬虫不会在交互时重新爬行页面...

<小时/>

你想与 Google、Bing 等竞争吗?如果您通过 robots.txt 善意地询问他们,他们可能不会关注您的链接。 ,或rel="nofollow" .

关于javascript - 如何使用哈希来屏蔽外部 URL 不被抓取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59863187/

相关文章:

javascript - Rails 4 - 将 Google Maps API JSON 返回值发送到 Controller

javascript - 如何在每个 VuetifyJS 组合框条目前添加一个图标?

javascript - Vue.js 'props' 在模板中工作,但在方法中未定义

javascript - 如何根据列表项 ID 对 HTML 列表进行排序

javascript - 服务字符串参数内的 Angular 转换为数组

vue.js - 在渲染期间停止对属性的空警告

typescript - Vue 3 中的错误 - 类型参数 'typeof import("../dist/vue")' is not assignable to parameter of type ' Public API Component'

javascript - VueJS 2 值绑定(bind)中的条件渲染

javascript - Vue : Show/Hide image based on its own src attribute

javascript - 使用自调用匿名函数