【问题标题】:Google Bot Reading Javascript IncorrectlyGoogle Bot 错误地读取 Javascript
【发布时间】:2013-07-14 23:22:18
【问题描述】:

在我正在处理的网站上,我们有一堆 jquery,它们根据在选择选项中选择的内容重定向到页面的下一级。更改功能工作正常,但谷歌网站管理员工具无法正确读取代码,并在 GWT 中返回一堆 404 错误。

var type = $('#select-type option:selected').attr('value')      ;
if (type == 'Masters' || type == 'Bachelors' || type == 'Associates')
{ 
    location.href = '/'+type+'/Degree-in-Criminal-Justice';
}

GWT 为 /Degree-in-Criminal-Justice 返回 404 错误,并忽略类型变量,它是有效 url 的一部分。

【问题讨论】:

  • 首先,你应该使用:var type = $('#select-type').val()

标签: jquery seo googlebot google-search-console


【解决方案1】:

Google Bot 如何知道他必须选择您选择中的每个选项才能进一步导航?

我提出以下建议:从包含链接的 HTML 块开始

Choose site:
<div id="choice">
    <a href="Masters/Degree-in-Criminal-Justice">Masters</a>
    <a href="Bachelors/Degree-in-Criminal-Justice">Bachelors</a>
    <a href="Associates/Degree-in-Criminal-Justice">Associates</a>
</div>

然后用 JavaScript 将其转换为可点击项:

  var choice = $("#choice")
  var choices = {}
  var select = $('<select>')
  select.append($('<option>'))
  choice.find('a').each(function(i,el){
      var text = $(el).text()
      choices[text] = el.href
      select.append($('<option>').val(text).html(text))
  })
  choice.empty()
  choice.append(select)
  select.change(function(val){
    var selectedValue = select.find('option:selected')[0].value
    if (selectedValue)
        location.href=choices[selectedValue]
  })

副作用:您摆脱了链接选择的 ifs。在这里摆弄:http://jsfiddle.net/lechlukasz/zru9Q/

【讨论】:

    猜你喜欢
    • 2021-07-15
    • 2022-11-03
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 2015-03-10
    相关资源
    最近更新 更多