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
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With