Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the hash part of the URL not available on the server side?

For example if I type in the URL:

http://www.foo.com/page.php?parameter=kickme#MOREURL

Then on the server there is no part: #MOREURL

Is possible to send or get these part to the server without jQuery AJAX?.

like image 340
CRISHK Corporation Avatar asked Sep 08 '10 02:09

CRISHK Corporation


People also ask

Is hash part of URL sent to server?

Fragment identifiers are not sent to the server. The hash fragment is used by the browser to link to elements within the same page.

Which part of the URL is hash?

The fragment identifier introduced by a hash mark # is the optional last part of a URL for a document. It is typically used to identify a portion of that document.

How do I add a hash to a URL?

The hash of a url can be found by creating a new URL Javascript object from the URL string, and then using its hash property to get the value of the hash fragment. Note that this will include the # character also. If the url does not contains a hash, then an empty string "" will be returned.

How do I know if a URL has a hash?

The task is to check whether an URL contains or not. This can be done by using the Location hash property in JavaScript. It returns the string which represents the anchor part of a URL including the hash '#' sign.


2 Answers

No, it is available to the browser only, so you have to deal it with Javascript. The server can not read it.

Explanation:
Basically the hash component of the page URL (the part following the # sign) is processed by the browser only - the browser never passes it to the server. This sadly is part of the HTML standard and is the same whether or not you are using IE or any other browser (and for that matter PHP or any other server side technology).

Here's what Wikipedia says about it:

The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the server. When an agent (such as a Web browser) requests a resource from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the fragment value. In the most common case, the agent scrolls a Web page down to the anchor element which has an attribute string equal to the fragment value. Other client behaviors are possible

like image 171
shamittomar Avatar answered Sep 18 '22 09:09

shamittomar


https://www.rfc-editor.org/rfc/rfc2396#section-4

When a URI reference is used to perform a retrieval action on the identified resource, the optional fragment identifier, separated from the URI by a crosshatch ("#") character, consists of additional reference information to be interpreted by the user agent after the retrieval action has been successfully completed. As such, it is not part of a URI, but is often used in conjunction with a URI.

like image 41
meder omuraliev Avatar answered Sep 19 '22 09:09

meder omuraliev