开发者

Strip off everything after #anchor including the #anchor

开发者 https://www.devze.com 2023-01-29 19:33 出处:网络
Change this... www.sample.com/sample.html#commentxxx?stuffhereIdontneed into this... www.sample.com/sample.html

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('#.*', '');
0

精彩评论

暂无评论...
验证码 换一张
取 消