tags:

views:

93

answers:

2

How to obtain anchor part of URL after # in JavaScript? This is related with http://stackoverflow.com/questions/1032242/php-question

+4  A: 

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!

MiffTheFox
A: 

You could use a regular expression:

var url = "http://nhs/search-panel.php#?patientid=2";
var hash = url.match(/^[^#]*#(.*)/)[1];

See also http://stackoverflow.com/questions/824040/doing-substring-in-window-location-hash

Gumbo