How do I remove a URL's hash sign and the text after it?
For example, the URL is http://www.website.com/home#content
I want the whole #content text to be removed.
How do I remove a URL's hash sign and the text after it?
For example, the URL is http://www.website.com/home#content
I want the whole #content text to be removed.
I think this is what you're looking for... (i.e. when you click a hyperlink that has a hash in its href, you want to strip out the hash and navigate to the remaining URL?)
<!DOCTYPE html>
<html>
<body>
<a id="someLink" href="/some_page#some_hash">Click Me</a>
<script src="http://code.jquery.com/jquery-2.2.4.min.js"></script>
<script>
$('#someLink').click(function (e) {
// Prevent normal navigation to the href (the full URL with hash)
e.preventDefault();
// Navigate to "/some_page" (everything to left of the first "#")
document.location = this.href.split('#')[0];
});
</script>
</body>
</html>