jspωiki
URI Fragment Identifiers

Overview#

URI Fragment Identifiers (or sometimes also called Same-Document Reference or anchor tag) are anything past the first "#" within the URI (or URL)

URI Fragment Identifiers is interpreted only by the local web browser and is typically NOT passed to the remote web server.

URI Fragment Identifiers, as defined in RFC 3986, as:#

The fragment identifier component of a URI allows indirect identification of a secondary resource by reference to a primary resource and additional identifying information. The identified secondary resource may be some portion or subset of the primary resource, some view on representations of the primary resource, or some other resource defined or described by those representations. URI Fragment Identifiers component is indicated by the presence of a number sign ("#") character and terminated by the end of the URI.
When a URI reference refers to a URI that is, aside from its URI Fragment Identifiers component (if any), identical to the base URI (Section 5.1), that reference is called a "same-document" reference. The most frequent examples of same-document references are relative references that are empty or include only the number sign ("#") separator followed by a fragment identifier.

URI Fragment Identifiers holds additional identifying information that provides direction to a secondary resource, e.g., a section heading (in an article) identified by the remainder of the URI. When the primary resource is an HTML document, the fragment is often an id attribute of a specific element and web browsers will make sure this element is visible.

Anything After the First "#" is a Fragment Identifier [2]#

Even if the first # appears to be contained within the host name, path or URI Query string – "#" always indicates where the URI Fragment Identifiers starts.

For example, here’s a URL that attempts to encode an HTML color and shape into the URI Query string:

http://example.com/?color=#ffff&shape=circle
Unfortunately, the "#" in the HTML color makes the rest of the URL a fragment identifier and the server will see a single, empty color parameter in the query string.

Changing A URI Fragment Identifiers Doesn’t Reload a Page but Does Create History#

Fragments have a couple of handy features. First, if you manually change a fragment URL from something like this:
http://www.httpwatch.com/features.htm#filter

to this:

http://www.httpwatch.com/features.htm#print
and the browser scrolls the page to the new location but does not reload the page.

However, it does add an entry in the browser’s history so that clicking the Back button will go back to the original location in the page.

These features are particular useful when used with Javacript to create linkable URLs and history for pages that either use top level HTML frames or update their content dynamically with AJAX calls.

URI Fragment Identifiers Are not Sent in HTTP Request Messages#

If you try using fragment URLs in an HTTP sniffer like HttpWatch, you’ll never see the URI Fragment Identifierss in the requested URL or Referer header. The reason is that the URI Fragment Identifiers is only used by the browser – it doesn’t affect which resource is returned from the server.

So do not expect to see URI Fragment Identifiers in your Server-side code.

RFC 7320#

Media type definitions (as per RFC 6838) SHOULD specify the fragment identifier syntax(es) to be used with them; other specifications MUST NOT define structure within the URI Fragment Identifiers, unless they are explicitly defining one for reuse by media type definitions.

For example, an application that defines common fragment identifiers across media types not controlled by it would engender interoperability problems with handlers for those media types (because the new, non-standard syntax is not expected).

URI Fragment Identifiers Security Considerations#

More Information#

There might be more information for this subject on one of the following: