Sometimes because of cache I add # in my url, like this:
http://www.example.com/#lang=3201954253
What I need is to check if there is #lang in url and remove it if present.
you can clear the hash.
window.location.hash = '';
or you can even use history api History Api. history.pushState and replaceState
history.replaceState() operates exactly like history.pushState() except that replaceState() modifies the current history entry instead of creating a new one.
window.history.replaceState( {} , 'foo', '/foo' );
You may try like this:
if(window.location.hash) {
// code
} else {
// code
}
or you may try this:
<script type="text/javascript">
if (location.href.indexOf("#") != -1) {
//code
}
</script>
If you want to remove it then you may try this:
window.location.hash = ''
On a side note:
You may try
window.location.href.split('#')[0]
to remove anything after # without refreshing your page.
window.location.href.split('#')[0] to remove the anything after # without refreshing your pagefunction removeHash() { window.history.pushState("", document.title, window.location.pathname); btn.disabled = !(location.hash || location.href.slice(-1) == "#"); }var tel = window.location.href;
if(tel.indexOf("#") > -1){
alert("found");
} else {
alert('not found')
}