Wednesday, November 14, 2007

base href and named anchors

This is just a rough note for now. I have always wanted to use the base href tag. With this you can have structure like this...

maindomain
maindomain\projects
maindomain\projects\bikeshop
maindomain\projects\bikeshop\map
maindomain\projects\bikeshop\about

Well, normally the root you are working with is maindomain but if you want to temporarily have your bikeshop project sitting in some sub folders you can and you can specify the base ref to acheive it, like this...

maindomain\projects\bikeshop\index.html

<head>
<base href="http://www.maindomain.com/projects/bikeshop">

And now any sub folders can be set up with relative links and will all look at the baseref. SWEET

One thing is not sweet. When you are in this file...
maindomain\projects\bikeshop\about\index.html
...and you jump to a named hyperlink within that document, you jump to the base href instead. Which is a complete pain.

After many hours of surfing it seems that good old PHP has an easy answer for us...

<p class="skiplink"><a class="skiplink" href="<?php echo $_SERVER['REQUEST_URI']; ?>#top" accesskey="2" >Skip over navigation</a></p>

This server request returns the actual URL of the document and sticks it into the page, so, your named hyperlink within the page is more fully qualified.

This probably makes no sense but it is very handy to me to write it down right now!

3 comments:

MarcPSummers said...

Perfect Solution - Thanks.

Salman Arshad said...

If you are interested in client side javascript based solution:

{a name="products"}{/a}

{a href="javascript:;" onclick="location.hash = 'products'; return false;"}products{/a}

Replace curly brackets with angle brackets. I am not being allowed to enter html code.

Unknown said...

Salman, thanks for the javascript tip. It's just what I needed and works great.