How to dynamically change a web page's title?

前端 未结 19 1743
遇见更好的自我
遇见更好的自我 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:40

    Use document.title. It will be useful for most things, but it will destroy SEO on your website.

    Example:

    document.write("title - " + document.title + "
    "); document.title = "New title here!"; // Notice: this will defeat purpose of SEO. Not useful for SEO-friendly sites. document.write("title - " + document.title + "
    ");
    body {
      font-family: Consolas, 'Courier New', monospace;
    }
    
    
      Old title
      

    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.

提交回复
热议问题