Page title is not changed by history.pushState

后端 未结 4 1311
一个人的身影
一个人的身影 2021-02-03 20:01

I\'ve just opened a blank HTML page with some little amount of base tags (like html, body, head, etc) in Google Chrome, and tried to execute the following command in console:

相关标签:
4条回答
  • 2021-02-03 20:33

    Currently, the title is being changed in all modern browsers using history.push(), but you have to change the URL. If you only add "#locationhash" it won't change the title, which makes sense.

    0 讨论(0)
  • 2021-02-03 20:35

    It seems current browsers don't support pushState title attribute. You can easily achieve the same thing by setting it in JS.

    document.title = "This is the new page title.";
    
    0 讨论(0)
  • 2021-02-03 20:39

    Following code will change the page title when you use history.pushState

    $(document).prop('title','your page title');
    

    It is working with IE also.

    0 讨论(0)
  • 2021-02-03 20:49

    Setting the title using document.title is not recommended if you want good SEO.

    History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports jQuery, MooTools and Prototype.

    Demo

    Source

    0 讨论(0)
提交回复
热议问题