We are working on a project using window.history.replacestate. Unfortunately we aren’t very good at javascript.
Essentially we are using it to replace any number of shortlinks to the ‘root’ link. For example :
domain.com/fJfk8
domain.com/9dkDl
domain.com/fjgdD
would all ‘appear’ as :
domain.com/nice_url
It doesn’t have to work so we’ll put the javascript in the page and in the browsers it does then great and if it doesn’t, they get the shortcode.
Note : we don’t want history !
So we are just using :
window.history.replaceState('Object','Nice URL Title', '/nice_url');
The question is that this appears to work but we don’t understand the ‘Object’ (data) part.
What exactly is it ?
You can set the
Objectparameter to arbritary data, which will be available in thestateparameter of theeventobject which is available in thepopstateevent.In other words, you can set it to whatever you want, to help you restore the webpage to the desired state when the user navigates through their history.
For more information, see the MDC documentation on window.history.