0

I have url as: /#profile/7 how to make it grab that last number from there? I'm looking for creating an mysql connection from that, SELECT something FROM somewhere WHERE id=':profile' Also, is it safe this way, is it even possible to make a connection? This is what I've got.

<script>
      var hash = window.location.hash.substring(6);
      alert (hash);
</script>
user2128056
  • 111
  • 1
  • 6
  • The hash is not sent to the server by default. see: http://stackoverflow.com/questions/317760/how-to-get-url-hash-from-server-side – Gaël Barbin Mar 14 '13 at 13:34

2 Answers2

1

You can use a regex:

var hash = window.location.hash.match(/\/(\d)/)[1]
Jeff Shaver
  • 3,315
  • 18
  • 19
0

Try with split() instead of substring:

var parts = window.location.hash.split('/');
var id = parts[parts.length - 1];
techfoobar
  • 65,616
  • 14
  • 114
  • 135