...

View Full Version : What does / and # in href "#" or "/" signify



effpeetee
01-04-2008, 01:03 PM
What does / and # in href "#" or "/" signify?
I have come accross them in some posters codes and cannot find the answer on Google or in my books.:confused:

Frank

VIPStephan
01-04-2008, 01:50 PM
The forward slash is used to denote the root directory, i.e. (a link with) a URL containing a leading slash like “/images/example.jpg” is an absolute URL that tells the browser to look for the image starting at the site root. It works the same way if you leave the rest off and just have the slash. I.e. a link like this: <a href="/">Home</a> would bring the visitor to the default file (typically the index page) of the root directory in the same way as a link like <a href="/test">Link</a> would bring the visitor to the default/index file of the /test directory.

The number sign in anchors is commonly used for links that aren’t supposed to go anywhere. Usually the number sign is a separator for a fragment identifier (http://en.wikipedia.org/wiki/Fragment_identifier), i.e. a link <a href="#comments>comments</a> will bring the visitor to the element/section of the current page that has the ID “comments” (e. g. <div id="comments">…</div>).

So, links that aren’t supposed to go anywhere are usually filled with a single number sign (for example for links that open new windows using javascript). However, I’ve read somewhere that this shouldn’t be done as it causes accessibility issues etc. I just can’t remember where I’ve read that.

effpeetee
01-04-2008, 03:46 PM
Thank you VIPStephan. That clears that up for me.

Frank

ahallicks
01-04-2008, 04:05 PM
I remember being told that using something such as '#n' in your links (that aren't supposed to go anywhere) stops the page jumping to the top, but is not semantic code because you are basically pointing to the location of a div that doesn't actually exist

felgall
01-04-2008, 07:53 PM
The # is actually a link to the top of the current page (anyone using it for links that are not supposed to go anywhere is using it incorrectly).

If the # is followed by something then that something is the id of the anchor point within the page that the link goes to. eg. #bottom puts the spot where <a id="bottom"></a> appears at the top of the screen (or as close as possible in there is insufficient content below it to fill the screen).

Apostropartheid
01-05-2008, 05:18 PM
Not necessarily an anchor. Anything which takes an ID may be pointed to by a fragment identifier.

felgall
01-05-2008, 10:12 PM
Not necessarily an anchor. Anything which takes an ID may be pointed to by a fragment identifier.


True for modern browsers. Older browsers required that it be an anchor and so using an anchor tag for it will work in more browsers.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum