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

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


当前回答

更新:根据SearchEngineLand上的评论和参考 大多数网络爬虫将索引更新的标题。下面的答案是过时的,但代码仍然适用。

You can just do something like, document.title = "This is the new page title.";, but that would totally defeat the purpose of SEO. Most crawlers aren't going to support javascript in the first place, so they will take whatever is in the element as the page title. If you want this to be compatible with most of the important crawlers, you're going to need to actually change the title tag itself, which would involve reloading the page (PHP, or the like). You're not going to be able to get around that, if you want to change the page title in a way that a crawler can see.

其他回答

代码是 文档。Title = 'test'

使用document.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!

我看不出如何通过Javascript改变页面标题将有助于SEO。大多数(或所有)搜索机器人不运行Javascript,只会读取最初加载的标题。

如果你想帮助SEO,那么你将需要在后端改变页面标题,并服务于不同版本的页面。