Hi I am building this website: http://www.freiheitmedia.com/en/. It is build with the Themify Ultra theme.
My goal is to get rid of the #something part in the url when scrolling or clicking on a link.
I need to do it with JavaScript/jQuery because there is no theme based solution and the support staff can't help me.
I already tested and know that the following code replaces the url as I want:
history.replaceState("",document.title,window.location.pathname + window.location.search);
Now, the problem is that I seemingly can't get the "hashchange" event to fire. I am putting the following code in the footer and the alert statement is not reached in both cases:
<script>
window.addEventListener("hashchange", function(e){
alert("hiii");
});
</script>
or
<script>
window.addEventListener("hashchange", function(e){
alert("hiii");
}, false);
</script>
I suspect that the hashchange event might be prevented by the theme's settings but it's just a guess.
Do you guys have any idea why "hashchange" is not firing?
From your clarifying comment:
The best way to do that would be to find the plugin that's responding to scroll events by updating the hash (which is meant to be helpful, presumably; taking you back to that part of the page if you bookmark it) and turn it off. Fighting for control of the hash with a plugin on the page is a bad idea.
Very much second-best to that:
Since
hashchangeisn't firing, the plugin must be usinghistory'sreplaceStateorpushStateor similar to set the hash, as that doesn't firehashchange. You could replace those functions with your own version that strips the hash fragment:Again, though, really it's best to find whatever is responding to the scroll event by adding hash fragments and disable it.