Search code examples
javascriptjquerybrowser-history

jQuery: Replace window.history entry


I have a site www.mysite.com/entry/1 with a div which opens when I click on a button.

When it opens I make a window.history.pushState(), for example:

www.mysite.com/entry/1#12345678

I can set filter in this opened div, so every time I set a filter, the hash value changes and I make a window.history.pushState("", "", url+newHash);

When I do this, for example, 10 times, I have 10 different URLs in my window.history.

Is it possible to overwrite this, so that I only have the last url-hash value in my history?

The reason is, that when I click on the browser's back button, the url should be www.mysite.com/entry/1 and I don't want to go through all hash values.

THANKS FOR ANY HELP!


Solution

  • Yes, you use replaceState (MDN, spec) rather than pushState.