Reputation: 817
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
Reputation: 454960
If you want a regex based solution, you can use:
window.location.href.replace('#.*', '');
Upvotes: 0
Reputation: 34622
Nathan's answer is good. For completeness' sake; here's the regex:
var stripped = window.location.href.replace(/#.*$/,'');
Upvotes: 17