我有一个网页,实现了一组选项卡每个显示不同的内容。单击选项卡不会刷新页面,而是隐藏/取消隐藏客户端的内容。
现在需要根据页面上选择的选项卡更改页面标题(出于SEO原因)。这可能吗?有人能建议一个解决方案,通过javascript动态改变页面标题,而不重新加载页面?
我有一个网页,实现了一组选项卡每个显示不同的内容。单击选项卡不会刷新页面,而是隐藏/取消隐藏客户端的内容。
现在需要根据页面上选择的选项卡更改页面标题(出于SEO原因)。这可能吗?有人能建议一个解决方案,通过javascript动态改变页面标题,而不重新加载页面?
当前回答
现代爬虫程序能够解析DOM中动态生成的内容,因此使用document。标题=…完全没问题。
其他回答
为了让任何爬虫程序注意到这个变化,您必须用一个新的标题重新提供页面。通过javascript这样做只会让人类读者受益,爬虫不会执行这些代码。
你可以使用JavaScript。一些机器人,包括谷歌,将执行JavaScript以获得SEO的好处(在SERP中显示正确的标题)。
document.title = "Google will run this JS and show the title in the search results!";
但是,这更复杂,因为您在不刷新页面或更改URL的情况下显示和隐藏选项卡。也许添加一个锚会像其他人所说的那样有所帮助。我可能需要收回我的回答。
有积极效果的文章: http://www.aukseo.co.uk/use-javascript-to-generate-seo-friendly-title-tags-1275/ http://www.ifinity.com.au/2012/10/04/Changing_a_Page_Title_with_Javascript_to_update_a_Google_SERP_Entry
不要总是假设bot不会执行JavaScript。 http://searchengineland.com/tested-googlebot-crawls-javascript-heres-learned-220157 谷歌和其他搜索引擎都知道,索引的最佳结果是实际终端用户将在浏览器中看到的结果,包括JavaScript。
代码是 文档。Title = 'test'
使用document.title。它对大多数事情都很有用,但它会破坏你网站上的SEO。
例子:
document.write("title - " + document.title + "<br>"); document.title = "New title here!"; // Notice: this will defeat purpose of SEO. Not useful for SEO-friendly sites. document.write("title - " + document.title + "<br>"); body { font-family: Consolas, 'Courier New', monospace; } <!DOCTYPE html> <html> <head><title>Old title</title></head> <body><p> Lorem ipsum dolor sit amet, at movet detraxit mediocritatem eam, nam iusto abhorreant ne. Ei pro debet adolescens voluptaria, eu minim scaevola conceptam vel. Vim ea torquatos constituto complectitur, usu eu civibus insolens eleifend. Ex ubique quaerendum his. </p></body> </html>
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!