SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Page Position-Specific Links

    Hey there. I noticed that sites like Wikipedia often have links that link you not only to a page, but a specific part of the page.

    How do I write my anchor tags so that I can achieve that?

    Also, would the links have to be on the same page that I'm having them link to, or can I put them on another page, and have them link directly to a specific part of a page?

  2. #2
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    You just add an id attribute to the section you want to link to. For example:

    Code html4strict:
    <h2 id="section">Section headline</h2>
    <p>...</p>

    You can then link to the specific id using the hash mark #, in this case http://www.example.com/pagename.html#section. You can do this both internally and externally, and even as a relative link (e.g. <a href="#section">Internal link</a>).

    You can add an id attribute to all tags. In some very old browsers, you can't use the id attribute, but will in stead have to use an anchor tag with a name attribute:

    Code html4strict:
    <h2><a name="section"></a>Section header</h2>
    <p>...</p>

    I generally don't do this anymore, as very few people still use browsers which doesn't recognise the id attribute, but you have to make that decision for yourself.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •