40

I was wondering is there any use of hash other than as an anchor in URL. I read about it here getting the full url including query string after hash . What is state information for the client? Please help.

Community
  • 1
  • 1
Naman
  • 991
  • 2
  • 10
  • 20

2 Answers2

48

The hash can be used also for single page applications, so instead of using it to navigate to a point in a page you use the hash as a means for navigated from page to page. The advantage of this is that it does not require a page refresh.

There is also a method called hashbanging which is used for single page applications and is used for helping ajax applications more indexible.

There are a few good articles on the subject

Dominic Green
  • 10,142
  • 4
  • 30
  • 34
  • +1, and nice reply! Is `#inbox` in `https://mail.google.com/mail/u/0/#inbox` a means for navigated from page to page without a page refresh? Is it implemented on server or client (web browser)? – Tim Jun 28 '17 at 15:04
12

Consider one page website, or website built fully on AJAX, without any page reloads.

#hash helps such applications to push state of the application to the client, this helps the application itself to be aware of the state and the client (and browser) to be aware of the state. This will also help the user to bookmark the application in its' current state and use back and forward buttons (browser history).

Arman P.
  • 4,314
  • 2
  • 29
  • 47
  • Is there any website there like this? – Naman Feb 18 '14 at 10:02
  • @Naman if you have any notification or new answers to your question, stackoverflow uses `#` *fragment identifier* to hight light it. – yashhy Feb 18 '14 at 10:04
  • @Naman Also take a look at this [template](http://www.profmedns.com/Theme/Shot/). I think it is mostly used in corporate applications (e.g. intranets) or website backends. – Arman P. Feb 18 '14 at 10:05
  • @pilot yashhy Isn't it same as fragment identifier? – Naman Feb 18 '14 at 10:07
  • @all Suppose there is website which takes input as get parameter and sends to server. And I put hash in input. URL will be formed with that hash parameter so whole value even after this hash is sent to server. What is the difference here? – Naman Feb 18 '14 at 10:11
  • @Naman I don't really get your example. Hash is basically used when no any page reload or form submit on page. So (for example) everything is sent to server with AJAX, server responds to AJAX request and `#something` is added to save some state. – Arman P. Feb 18 '14 at 10:16
  • @arman Okay, There is a website which takes some input from user and store it somewhere. Now, in the input field, I type - naman#jain . Now a url will be formed like - www.website.com/?name=naman#jain . I am saying #jain is also sent to server. As I read about it after # browser ignores everything. Correct me if I am wrong. – Naman Feb 18 '14 at 10:22
  • @Naman Your # in POST or GET parameter will be URL Encoded to `%23` when sending it and URL decoded on server side automatically. So the browser always know which is simple hash and which is hash in parameter value. – Arman P. Feb 18 '14 at 10:31
  • @arman So that means after ? every thing is parameter and sent to server and before ?, # is used as an anchor? – Naman Feb 18 '14 at 10:33
  • 1
    @Naman # (hash, anchor, state) will be also after ?, but all hashes (#) that are part of parameter will be url encoded (will turn to `%23`). I'm not sure for your case, it depends on usage case, but you can try it on yourself and let me know in comments with working example. – Arman P. Feb 18 '14 at 10:40