gravityboy
gravityboy

Reputation: 817

Strip off everything after #anchor including the #anchor

Change this...

www.sample.com/sample.html#commentxxx?stuffhereIdontneed

into this...

www.sample.com/sample.html

I have it in a link so I think I need a regex?

document.write("<a href='"+ window.location.href.replace('?????', '') +  
"?ThisIsAppendedLater'>sample</a>");  

Upvotes: 5

Views: 2335

Answers (4)

codaddict
codaddict

Reputation: 454960

If you want a regex based solution, you can use:

window.location.href.replace('#.*', '');

Upvotes: 0

Linus Kleen
Linus Kleen

Reputation: 34622

Nathan's answer is good. For completeness' sake; here's the regex:

var stripped = window.location.href.replace(/#.*$/,'');

Upvotes: 17

yurib
yurib

Reputation: 8147

url.substring(0,url.indexOf("#"))

Upvotes: 1

Nathan
Nathan

Reputation: 11149

window.location.hash = '';

Upvotes: 7

Related Questions