Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the anchor part of a URL being sent to a web server?

Tags:

browser

ajax

url

Say, there's a URL, http://www.example.com/#hello.

  1. Will the #hello thing be sent to the web server or not, according to standards?
  2. How do modern browsers act?
like image 971
codeholic Avatar asked Jun 18 '10 05:06

codeholic


People also ask

What is the anchor part of a URL?

The anchor text is also known as the link label or link title. The words contained in the anchor text help determine the ranking that the page will receive by search engines such as Google or Yahoo and Bing. Links without anchor text commonly happen on the web and are called naked URLs, or URL anchor texts.

What is an anchor in a website?

An anchor tag, or anchor link, is a web page element that links to another location on the same page. They are typically used for long or text-heavy pages so that visitors can jump to a specific part of the page without having to scroll as much.

What does the anchor element do in HTML?

An anchor is a piece of text which marks the beginning and/or the end of a hypertext link. The text between the opening tag and the closing tag is either the start or destination (or both) of a link. Attributes of the anchor tag are as follows.

What are anchor links in HTML?

The <a> HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address.


2 Answers

The answer to this question is similar to the answers for Retrieving anchor link in URL for ASP.NET.

Basically, according to the standard at RFC 1808 - Relative Uniform Resource Locators (see Section 2.4.1), it says:

"Note that the fragment identifier is not considered part of the URL."

As stephbu pointed out, "the anchor tag is never sent as part of the HTTP request by any browser. It is only interpreted locally within the browser".

like image 92
3 revs, 3 users 72% Avatar answered Sep 20 '22 18:09

3 revs, 3 users 72%


The hash variables aren't sent to the web server at all.

For instance, a request to http://www.whatismyip.org/#test from Firefox sends the follow HTTP request packet

GET / HTTP/1.1
Host: www.whatismyip.org
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Cache-Control: max-age=0

You'll notice the # is nowhere to be found. Pages you see using # as a form of navigation are doing so through javascript. This parameter is accessible though the window.location.hash variable

like image 45
Jamie Wong Avatar answered Sep 17 '22 18:09

Jamie Wong