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?
doc开发者_C百科ument.write("<a href='"+ window.location.href.replace('?????', '') +
"?ThisIsAppendedLater'>sample</a>");
Nathan's answer is good. For completeness' sake; here's the regex:
var stripped = window.location.href.replace(/#.*$/,'');
window.location.hash = '';
url.substring(0,url.indexOf("#"))
If you want a regex based solution, you can use:
window.location.href.replace('#.*', '');
精彩评论