Barlas Apaydin Barlas Apaydin - 2 months ago 5x
jQuery Question

How can I replace a window's URL hash with another response?

I am trying to change a hashed URL (document.location.hash) with the replace method, but it doesn't work.

var anchor = document.location.hash;
//this returns me a string value like '#categories'


//try to change current url.hash '#categories'
//with another string, I stucked here.


I dont want to change/refresh page, I just want to replace URL without any responses.

Note: I don't want to solve this with a href="#food" solution.


Either use location or window.location instead of document.location as the latter is a non-standard.

window.location.hash = '#food';

This will replace the URL's hash with the value you set for it.