Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

history.pushstate not updating title

I am using AJAX to load main content of the page. Using history.pushstate(Object:State, String:Title, String:URL) - I am able to update the URL in the address bar and navigate back in the history.

However the title parameter appears to have no effect. Neither does the window title change nor the title of the entries in the 'history list' (perhaps both of them are same anyway).

What am I doing wrong?

Update: title param is simply ignored in chrome. http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2010-June/026827.html

like image 910
Ujjwal Singh Avatar asked Dec 11 '12 09:12

Ujjwal Singh


2 Answers

The title parameter is not the window title.
It may be used as a title of the state but some browsers like Chrome simply ignore it.

like image 88
Tetaxa Avatar answered Nov 15 '22 17:11

Tetaxa


I doesn't know why that works like that, but because of comment of Rounin which are next:

I have window.history.pushState(myStateObject, myNewTitle, myNewURL); document.title = myNewTitle; working in Firefox 72 in Jan 2020. I have no idea how it's never occurred to me before that a document.title can be reset live. Excellent heads up.

I've suddenly found that in Firefox 91.0b9 you have to put pushState firstly, and secondly you have to change title. And then history manager in Ff 91.0b9 changing exact page that pushed state and not simular closer page with slightly different uri. In my case if document.title changed first, history management thing changes last two records with simular links of the site.

For example if some /page will be changed to /page/2, and you change title and then will make pushState, then both records titles will be changed to that one that you specified in document title or may be it's related to title in pushState. So when document.title called secondly it is works normally

Example (works):

window.history.pushState(myStateObject, myNewTitle, myNewURL);
document.title = myNewTitle;

And not like it is probably suppose to be (not works):

document.title = myNewTitle;
window.history.pushState(myStateObject, myNewTitle, myNewURL);

Thank you to the Rounin!

like image 39
b0s.at.works Avatar answered Nov 15 '22 19:11

b0s.at.works