Forum Moderators: mack

Message Too Old, No Replies

How to link to part of a web page

Linking help.

         

kodaks

9:49 pm on Aug 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am wondering how to link to a specific part of a webpage. For example, if I wanted to link back up to the top of a long page, what would I have to do? Thanks!

coopster

9:55 pm on Aug 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It's all in the links [w3.org].

kodaks

10:04 pm on Aug 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, I'll look into it.

Reid

11:32 am on Sep 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use the 'name' attribute
eg. the link points to another link on the same document.

link <A href= "#widget" name= "blah">top of document</a>

points to this link (located at the top of document)

<A href= "#blah" name= "widget">Widgets</a>

so widget points to blah and blah points to widget.

pageoneresults

12:28 pm on Sep 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You may want to go one step further and bybass the name attribute as it is invalid markup in XHTML. The id attribute is preferred over the name attribute and it will save you a lot of time and excess code. Just throw the id in any of the elements where you want to provide a bookmark on the page.

<h1 id="top"></h1>

<a href="top">Back to Top</a>

Remember, you can only use one instance of the named id on a page. So, if you needed two id="top", you'll need to come up with a second id name so they are unique and only used once on a page.

Reid

7:17 am on Sep 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thats interesting.
perhaps the name attribute can be a lot simpler in some cases
specifically 'top of document' where several links may point to one name in a long document.

(located at top)
<a href= "index.html" name= "top">Home</a>

(further down)
<a href= "#top">top of document</a>

(further down)
<a href= "#top">top of document</a>

(further down)
<a href= "#top">top of document</a>