1

I have urls like:

http://stackoverflow.com#tab1
http://stackoverflow.com/something#tab1#tab3
http://stackoverflow.com/links.html#tab2#tab1#tab4

How can I remove everything after the hash sign, so I can keep a simple URL like:

http://stackoverflow.com
http://stackoverflow.com/something
http://stackoverflow.com/links.html

Thanks in advance

Abu Rayane
  • 241
  • 1
  • 14

1 Answers1

2

simply use .split() the string and get the first object

var url = "http://stackoverflow.com/something#tab1#tab3";

console.log(url.split("#")[0]);

Dynamic url

console.log(window.location.href.split("#")[0]);

FIDDLE

Sudharsan S
  • 15,336
  • 3
  • 31
  • 49