Dan
Dan

Reputation: 1295

Removing # and its value from url

I have seen posts on here to remove the hash value from a url... but how do remove the value and the # itself.

for example if a url was

mysite.com

and when a user navigates through the one page application the url might change to

mysite.com#mytest

so when they reload it i just want it to show

mysite.com and  not mysite.com#mytest

these two just remove the value

location.hash = 'home'; 

window.location.replace("#");

thanks

Upvotes: 0

Views: 59

Answers (2)

Charlie Gorichanaz
Charlie Gorichanaz

Reputation: 1204

var href = window.location.href;
var index = href.indexOf('#');
if ( index > 0) {
  window.location = href.substring(0, index);
}

Upvotes: 1

Rishabh
Rishabh

Reputation: 2021

I don't think it's possible to remove the hash without reloading the page.

Upvotes: 1

Related Questions