You are here: Re: HTML HREFS - confused... « HTML « IT news, forums, messages
Re: HTML HREFS - confused...

Posted by Andy Dingley on 04/24/06 12:45

Domestos wrote:

> I've read till I am blue in the face examples and thoughts on proper use of
> the HREF tag.

You probably have trouble with "URIs" rather than href itself.

href and src are used confusingly in HTML. <img> has src, <a> has href.
Try thinking of them as src for "Stuff I'm using right now on this
page" and href for "Stuff I might use, if the use selects that link and
goes somewhere"

href is an attribute, not a tag. In this newsgroup we care.

> my local development 'index.html' exists at...

URIs (roughly) come in three sorts. Absolute, relative, and
root-relative.

A page of
http://example.com/pages/index.htm
might use any of the following URIs to point to an image in the same
location.

Absolute
http://example.com/images/foo.jpg

Relative
.../images/foo.jpg
another_image_directory_under_pages/bar.jpg
bat.jpg

Root-relative
/images/foo.jpg

They all work equally well, but their portability (robustness when the
source page is moved) varies. They all break if you move the image
resource.

Absolute always points to the same site. Doesn't care where you use it
from. Handy for referring to external sites, and will keep working
between your "dev" and "live" sites.

Relative is what you should use instead for referring to assets on your
own site. It "follows" whichever host you're currently loading the page
from. It also follows the page's directory around (handy for lots of
directories and images kept with their pages).

Root-relative paths are relative for the host, but absolute for the
path on that host. For moving servers they work like relative URIs, but
for moving pages around they keep pointing to the same place on the
server. Handy for "site furniture" that's shared between many pages,
rather than the page-specific assets.


In general, set your server up with an "images" directory (or somesuch
name) and keep the shared stuff in there (logos, page background)
referring to it with root-relative URIs.

Use lots of directories and lots of default pages (index.htm or
equivalent). Make most page URIs of the form
"http://example.com/pages_about_fish/" and don't bother specifiying the
default page name.

Place page-specific images into the directory with their page. Use
relative URIs (probably just "mullet.jpg") to refer to them from the
<img src="" > attribute..

Only use absolute URIs for external links <a href="http://google.com" >

Always use absolute URIs for external links.


> My webpage exists at
> http://www.mywebsite.com/index.html

That's not your site, is it ? Use "example.com" if you want an
example, otherwise use the real site so that we can see the real
problem.

If "mywebsite.com" really is your work, then it's cluelessness beyond
_any_ help whatsoever. Technical "shiny things" grabbing of the newset
toy in the box, used for an _entirely_ inappropriate purpose (the AJAX
nav menu)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация