javascript - How to set the title of the entry that the browser displays for history.pushState? -


i use history.pushstate( stateobject, title, url ) push new entries history stack of browser. despite name second parameter title not set title of entry displayed in browser's history. if understand correctly title reserved future use , ignored browsers. should safe pass '' here , findings support this.

hence, wonder how set label user see in history , thought document.title job. code looks this

var mytitle = /* code generate title here */ var myurl = /* code generate url here */ var mystate = /* code generate realizable state object here */      document.title = mytitle; history.pushstate( mystate, '', myurl ); // 2nd parameter can mytitle; has no effect on major browsers 

however, not work expected. more precisely encounter strange off-by-one error. seems pushstate not create new history entry using new document.title previous title. guess problem dom not updated after js leaves current call stack. document.title = mytitle becomes effective after pushstate.

the note below bullet point 8 @ chapter 5.5.2 of html5 specification of w3c says:

the title purely advisory. user agents might use title in user interface.

this behaviour implemented major browsers. howerver ui , new title updated after js function returns.

any solutions?

the popstate event fired when active history entry changes. if history entry being activated created call history.pushstate() or affected call history.replacestate(), popstate event's state property contains copy of history entry's state object.

window.addeventlistener('popstate', function(e) {   var character = e.state;        document.title = "title | ";  }); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -