【问题标题】:add rel='nofollow' in haml javascript filter在haml javascript过滤器中添加rel ='nofollow'
【发布时间】:2015-12-09 14:35:35
【问题描述】:

我正在尝试将 rel='nofollow' 添加到 javascript 的脚本标记中。目的是告诉机器人不要跟随脚本标签中的链接。但是,我不知道该怎么做。

我得到的最接近的是这样说的:

%script{rel='nofollow', type='text/javascript'}
  :cdata
    $.ajax({url: '/onepiece'});

但这会引发Uncaught SyntaxError: Unexpected token < 错误,因为

<script rel="nofollow" type="text/javascript">
    <![CDATA[

被渲染。我认为应该呈现的应该是

<script rel="nofollow" type="text/javascript">
    //<![CDATA[

还有其他使用haml的方法吗?

【问题讨论】:

  • 该代码不会呈现任何内容,它会给您一个undefined method `map' for "nofollow":String 错误。

标签: ruby-on-rails haml


【解决方案1】:

在 HTML5 中,nofollow 关键字只能应用于 aarea 元素。 (来源:W3C recommendation on html5 links)。此外,script 元素没有 rel 属性。

如果您要阻止的页面在您的域内,我建议您这样做in robots.txt 应该会阻止大多数机器人抓取该页面。

希望有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-26
    • 2014-12-15
    • 1970-01-01
    • 2012-11-30
    • 1970-01-01
    • 2020-02-28
    • 1970-01-01
    • 2011-08-04
    相关资源
    最近更新 更多