Reset everything after #anchor, including #anchor

Change it ...

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

in it...

www.sample.com/sample.html

I have a link, so I think I need a regular expression?

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

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

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

window.location.hash = '';

+7
source

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

+1
source

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

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

Source: https://habr.com/ru/post/1778911/


All Articles