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
3

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.