How do you obtain the anchor part of a URL in JavaScript?

javascript

Solution

To get the "anchor part" of the current page, you can use:

var hash = window.location.hash;

Then, based on your question link, you want to send it to a PHP script. You can do this with a JavaScript redirect like so:

window.location = "myscript.php?hash=" + encodeURIComponent(hash);

However, this won't work for users without JavaScript enabled, so be sure to have a `<noscript>` message ready!

Problem

How to obtain anchor part of URL after `#` in JavaScript? This is related with How to obtain anchor part of URL after # in php

Original source