我有一个网页,实现了一组选项卡每个显示不同的内容。单击选项卡不会刷新页面,而是隐藏/取消隐藏客户端的内容。

现在需要根据页面上选择的选项卡更改页面标题(出于SEO原因)。这可能吗?有人能建议一个解决方案,通过javascript动态改变页面标题,而不重新加载页面?


当前回答

为了让任何爬虫程序注意到这个变化,您必须用一个新的标题重新提供页面。通过javascript这样做只会让人类读者受益,爬虫不会执行这些代码。

其他回答

我使用一个单独的头,并包括它使用php,在头我使用:

<?php
if (!isset($title)){
    $title = "Your Title";
  }
  else {
    $title = $title;
  }
 ?>
<head>
<title><?php echo $title; ?></title>

然后在每一页我使用:

<?php
  $title = "Your Title - Page";
  include( "./header.php" );
?>

使用文档。标题是如何在JavaScript中完成它,但这应该如何协助SEO?机器人通常不会在遍历页面时执行javascript代码。

也许你可以在一个字符串中加载你的标题上所有的选项卡标题,然后一旦你加载其中一个选项卡,通过javascript改变标题

首先把你的标题设置为

my app | description | contact | about us | 

一旦你加载一个标签运行:

document.title = "my app | tab title";

最简单的方法是从index.html中删除<title>标签,并包含

<head>
<title> Website - The page </title></head>

在网络的每一页。蜘蛛会发现这一点,并将显示在搜索结果:)

Google mentioned that all js files rendered but in real, I've lost my title and another meta tags which had been provided by Reactjs on this website and actually lost my position on Google! I've searched a lot but it seems that all pages must have pre-rendered or using SSR(Server Side Rendering) to have their SEO-friendly protocole! It expands to Reactjs, Angularjs , etc. For short, Every page that has view page source on browser is indexed by all robots, if it's not probably Google can index but others skip indexing!