Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Navigation Bar: Use Absolute Referencing? 1

Status
Not open for further replies.

SSJpn

Technical User
Oct 7, 2002
259
US
I have a navigation bar that I want to put on each page. I don't want to use frames.

I heard that you are supposed to use relative referencing when linking to other pages on the same site. The problem is, I don't want to make changes to the navigation bar for each page.

How can I have a navigation bar that I can use for all my pages (no matter what directory the page is in) so that the links work?

Thanks,

SSJpn
 
Reference every page relative to the root directory. For example, say you want to reference


from somewhere in the mcgonagall-online.org.uk site. You could say
[tt]
<a href=&quot;[/tt]
but it's a bit unwieldy, and if you changed domain names for any reason you'd have to change any links. Conversely, something like
[tt]
<a href=&quot;../poems/pgdisaster.htm&quot;>
[/tt]
only works from particular parts of the site. When you reorganise the site, your links could break. The best way to do links, therefore, is like this:
[tt]
<a href=&quot;/poems/pgdisaster.htm&quot;>
[/tt]
where the link is evaluated relative to rather than the current file. Incidentally, to reference the home page with this method, just do
[tt]
<a href=&quot;/&quot;>
[/tt]


-- Chris Hunt
 
Chris Hunt,

Thanks for the input. Thats exactly what I need!

But.. how does the server know if im using relative referencing from the current file or from the root directory?

Does it just try both ways and sees which way works?

Can I use relative referencing from another place besides the current directory and root directory?


SSJpn
 
Also,

What if I have the following setup:

index.html
/ / \
pen(dir) pencil(dir)
|
metal(dir)
a.html
b.html
pen(dir)
|
b.html

now, from a.html... if I were to say href=&quot;/pen/b.html&quot;,
which b.html file will i get? how does it know if im referencing from the root or from the current file?
 
If you start your partial URL with a leading / it'll be relative to the root. If you don't it'll be relative to the current file's directory.

So &quot;/pen/b.html&quot; will always point to the b.html higher in the tree, wherever you put it. &quot;pen/b.html&quot; (no leading /) will reference the same file if the link appears in index.html, but to the lower b.html if it appears in a.html.

The browser works by looking at the link URL you've written and fills in any blanks by copying the relavant bits from the current page's URL. If you look at the status bar when you hover your mouse over a link, you can see the URL that the browser builds up in this way.

-- Chris Hunt
 
Chris,

Makes perfect sense. Thanks!!

SSJpn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top