Questions tagged [fragment-identifier]

The fragment-identifier is the part of the URI/URL following the hash symbol. In the case of `http://mysite.com/page/#/one` then `/one` would be the fragment-identifier.

The fragment-identifier is the part of the URI/URL following the hash symbol. In the case of http://mysite.com/page/#/one then /one would be the fragment-identifier.

In URIs a hashmark # introduces the optional fragment near the end of the URL. The generic RFC 3986 syntax for URIs also allows an optional query part introduced by a question mark ?. In URIs with a query and a fragment, the fragment follows the query. Query parts depend on the URI scheme and are evaluated by the server — e.g., http: supports queries unlike ftp:. Fragments depend on the document MIME type and are evaluated by the client (Web browser). Clients are not supposed to send URI-fragments to servers when they retrieve a document, and without help from a local application (see below) fragments do not participate in HTTP redirections.

A URI ending with # is permitted by the generic syntax and could be considered as a kind of empty fragment. In MIME document types such as text/html or any XML type, empty identifiers to match this syntactically legal construct are not permitted. Web browsers typically display the top of the document for an empty fragment.

The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the web server — of course the server typically helps to determine the MIME type, and the MIME type determines the processing of fragments. When an agent (such as a Web browser) requests a web 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 document type and fragment value.

For more info see wiki.

243 questions
911
votes
20 answers

How can you check for a #hash in a URL using JavaScript?

I have some jQuery/JavaScript code that I want to run only when there is a hash (#) anchor link in a URL. How can you check for this character using JavaScript? I need a simple catch-all test that would detect URLs like…
Philip Morton
  • 129,733
  • 38
  • 88
  • 97
842
votes
15 answers

Should I make HTML Anchors with 'name' or 'id'?

When one wants to refer to some part of a webpage with the "http://example.com/#foo" method, should one use

Foo Title

or

Foo Title

They both work, but are they equal, or do they have semantic differences?
Henrik Paul
  • 66,919
  • 31
  • 85
  • 96
765
votes
6 answers

What's the shebang/hashbang (#!) in Facebook and new Twitter URLs for?

I've just noticed that the long, convoluted Facebook URLs that we're used to now look like this: http://www.facebook.com/example.profile#!/pages/Another-Page/123456789012345 As far as I can recall, earlier this year it was just a normal…
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
583
votes
11 answers

How can I detect changes in location hash?

I am using Ajax and hash for navigation. Is there a way to check if the window.location.hash changed like this? http://example.com/blah#123 to http://example.com/blah#456 It works if I check it when the document loads. But if I have #hash based…
MilMike
  • 12,571
  • 15
  • 65
  • 82
422
votes
18 answers

How to remove the hash from window.location (URL) with JavaScript without page refresh?

I have URL like: http://example.com#something, how do I remove #something, without causing the page to refresh? I attempted the following solution: window.location.hash = ''; However, this doesn't remove the hash symbol # from the URL.
Tom Lehman
  • 85,973
  • 71
  • 200
  • 272
304
votes
14 answers

Change the URL in the browser without loading the new page using JavaScript

How would I have a JavaScript action that may have some effects on the current page but would also change the URL in the browser so if the user hits reload or bookmark, then the new URL is used? It would also be nice if the back button would…
Steven Noble
  • 10,204
  • 13
  • 45
  • 57
248
votes
21 answers

How to detect if URL has changed after hash in JavaScript

How can I check if a URL has changed in JavaScript? For example, websites like GitHub, which use AJAX, will append page information after a # symbol to create a unique URL without reloading the page. What is the best way to detect if this URL…
AJ00200
  • 16,327
  • 7
  • 23
  • 21
169
votes
19 answers

Modifying location.hash without page scrolling

We've got a few pages using ajax to load in content and there's a few occasions where we need to deep link into a page. Instead of having a link to "Users" and telling people to click "settings" it's helpful to be able to link people to…
Chris Barr
  • 29,851
  • 23
  • 95
  • 135
153
votes
4 answers

URL Fragment and 302 redirects

It's well known that the URL fragment (the part after the #) is not sent to the server. I do wonder though how fragments work when a server redirect (via HTTP status 302 and Location: header) is involved. My question is really two-fold: If the…
levik
  • 114,835
  • 27
  • 73
  • 90
144
votes
6 answers

How to get Url Hash (#) from server side

I know on client side (javascript) you can use windows.location.hash but could not find anyway to access from the server side. I'm using asp.net.
Ricky Supit
  • 3,310
  • 5
  • 26
  • 20
143
votes
7 answers

Getting URL hash location, and using it in jQuery

I'd like to get the value after a hash in the URL of the current page and then be able to apply this in a new function... eg. The URL could be www.example.com/index.html#foo And I would like to use this in conjunction with the following piece of…
Robbie White
  • 1,558
  • 2
  • 11
  • 8
107
votes
4 answers

Can you use hash navigation without affecting history?

I'm afraid it might be impossible but is there a way to change the hash value of a URL without leaving an entry in the browser's history and without reloading? Or do the equivalent? As far as specifics go, I was developing some basic hash navigation…
user241244
95
votes
7 answers

Handle URL fragment identifier (anchor) change event in Javascript

How can I write the Javascript callback code that will be executed on any changes in the URL fragment identifier (anchor)? For example from http://example.com#a to http://example.com#b
93
votes
3 answers

List of valid characters for the fragment identifier in an URL?

I'm using the fragment identifier to create a permalink for AJAX events in my web app similar to this guy. Something like: http://www.myapp.com/calendar#filter:year/2010/month/5 I've done quite a bit of searching but can't find a list of valid…
sohtimsso1970
  • 3,216
  • 4
  • 28
  • 38
85
votes
2 answers

ASP.Net MVC RedirectToAction with anchor

I have the following problem: For example I have route like this: routes.Add(new Route("forums/thread/{threadOid}/last", new MvcRouteHandler()) Defaults = new RouteValueDictionary( new { controller = "Thread", action…
inikulin
  • 913
  • 1
  • 8
  • 8
1
2 3
16 17