0

Can you please let me know how to clean a hashed URL like this

domain.com/2.html#box1

to

domain.com/2.html

by removing the #box1 (the # and everything after that). I already tried this

if (location.href.indexOf("#") > -1) {
    location.assign(location.href.replace(/\/?#/, "/"));
} 

but it generate a URL like

domain.com/2.html/box2
Behseini
  • 6,066
  • 23
  • 78
  • 125

1 Answers1

1

Check demo for working example.Bellow regex give all content after #(Containing #) and you just have to replace it with "".

a.replace(/#\w*/,"")

Demo

Mayur Patel
  • 1,741
  • 15
  • 32