How to dynamically change a web page's title?

前端 未结 19 1482
遇见更好的自我
遇见更好的自我 2020-11-22 08:05

I have a webpage that implements a set of tabs each showing different content. The tab clicks do not refresh the page but hide/unhide contents at the client side.

No

19条回答
  •  一生所求
    2020-11-22 08:22

    Since search engines ignore most javascript, you will need to make it so that search engines can crawl using the tabs without using Ajax. Make each tab a link with an href that loads the entire page with that tab selected. Then the page can have that title in the tag.

    The onclick event handler can still load the pages via ajax for human viewers.

    To see the pages as most search engines see them, turn off Javascript in your browser, and try to make it so that clicking the tabs will load the page with that tab selected and the correct title.

    If you are loading via ajax and you want to dynamically change the page title with just Javascript, then do:

    document.title = 'Put the new title here';
    

    However, search engines will not see this change made in javascript.

提交回复
热议问题