简体   繁体   English

SEO机器人是否始终遵循A标记的href属性中的url,即使使用Javascript拦截了点击/点击?

[英]Do SEO bots always follow the url in the href attribute of an A tag, even if the click/tap is intercepted with Javascript?

Suppose I have a regular A tag with a proper URL in its href attribute (foo.com). 假设我在其href属性(foo.com)中有一个带有正确URL的常规A标签。 Now, suppose I intercept the click (or tap) event of the A with a JavaScript function so, instead of performing the default action (navigate to foo.com) I can do something else first (fade out the content, for example), then navigate to a different URL (otherfoo.com). 现在,假设我使用JavaScript函数拦截了A的click(或tap)事件,因此,除了执行默认操作(导航至foo.com)之外,我还可以先做其他事情(例如淡出内容),然后导航到其他URL(otherfoo.com)。

  1. Would this affect SEO? 这会影响SEO吗? (meaning, will the bots get confused?) (意思是,机器人会感到困惑吗?)
  2. Would the bot follow the url in the href attribute (foo.com) or would it follow through the JavaScript function (and navigate to otherfoo.com)? 机器人会遵循href属性(foo.com)中的url还是遵循JavaScript函数(并导航至otherfoo.com)?

By "bots" and "SEO" I am mostly referring to Google, but broader answers would be great as well. 我主要指的是“机器人”和“ SEO”,但更广泛的答案也将是不错的选择。

tl:dr TL:博士

No, typical crawler doesn't evaluate javascript (to that extent) as it, in the effect, serves no real purpose - only more confusion. 不,典型的搜寻器不会评估javascript(在某种程度上),因为它实际上没有任何实际目的-只会造成更多混乱。

Disclaimer 放弃

Crawlers can probably scan javascript or CSS to obtain other info, which could affect sorting - but this is irrelevant in the scope of this questions. 爬虫可能可以扫描javascript或CSS来获取其他信息,这可能会影响排序-但这与本问题的范围无关。

Further more google crawler parses javascript but this seems to have effect on generated DOM tree, not callbacks which can be infinitely complex and would leave a gap for unknown state of the output - google wouldn't know if it has the links right or not. 更多的Google搜寻器会解析javascript,但这似乎会对生成的DOM树产生影响,而不是对可能无限复杂的回调产生影响,并且会在输出的未知状态上留下空白-谷歌不知道它是否具有正确的链接。

In many javascript interpreters I have noticed a javascript until onload scheme used to get proper DOM tree. 在许多JavaScript解释器中,我注意到一个javascript until onload用于获取正确DOM树的javascript until onload方案javascript until onload HTML to PDF creators (the better ones) can be an example. HTML到PDF创建者(更好的创建者)就是一个例子。 Google will be similar I guess. 我猜Google将会类似。

Thoughts on that 关于这个的想法

Ultimately, this is up to the implementation. 最终,这取决于实现。 But while it's technically possible to evaluate the javascript on your site and index javascript redirects, it's highly error prone and would not serve a practical purpose. 但是,尽管从技术上来说,可以评估您网站上的javascript并为javascript重定向建立索引,但它容易出错,因此无法实际使用。

If nothing else, you could bypass check that by passing fake javascript files to the crawler, which usually identifies itself by User-Agent header. 如果没有其他问题,您可以通过将伪造的javascript文件传递给搜寻器来绕过检查,该文件通常由User-Agent标头标识。

Definitely do not rely on this. 绝对不要依靠这一点。 I think you should make a hidden (to the user) link to any content you want to index but is linked by javascript. 我认为您应该对要索引但由javascript链接的任何内容建立一个(向用户)隐藏链接。 Use hiding by CSS class though, in case some search engine thought it's smart to ignore inline style display:block nodes. 不过,如果某些搜索引擎认为忽略内联样式display:block节点是明智的,则使用CSS类隐藏。

<a href="javascript.php" class="only-seen-by-crawlers">Javascript linked page</a>

Or just generally don't use javascript on links as it makes no sense in sane scenarios. 或者只是通常不要在链接上使用javascript,因为在合理的情况下这没有任何意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM