PDA

View Full Version : Jump to the content


neo_philiac
10-06-2006, 01:37 PM
Hey guys! I was just wondering if there is a jscript code to jump to the middle (or where my content is) of the page if i click on the link on the same page. if not how would you do it anyways?

rlemon
10-06-2006, 01:45 PM
<a href="#content">jump to content</a>


...page...

<a name="content">Content!</a><!-- you do not need text in the link -->
...content...

http://www.w3.org/TR/html401/struct/links.html#h-12.1.1


in js you would utalize element.scrollTop

Bill Posters
10-06-2006, 05:10 PM
So long as you're targeting modern browsers (e.g. IE5+, FF, Opera, Safari, etc…), you don't need to use named anchors at all.
You can use existing element id values as the destinations for fragment anchors.

e.g.
<a href="#content">Jump to main content</a>



<div id="content">



</div>
(* I used "…main content" as this helps screen readers interpret the word 'content' correctly.)

rlemon
10-06-2006, 10:09 PM
So long as you're targeting modern browsers (e.g. IE5+, FF, Opera, Safari, etc…), you don't need to use named anchors at all.
You can use existing element id values as the destinations for fragment anchors.

e.g.
<a href="#content">Jump to main content</a>



<div id="content">



</div>
(* I used "…main content" as this helps screen readers interpret the word 'content' correctly.)



if your going to push accesability then why limit the 'jump' link to 'new' browsers.

it's no extra work to place a "deprecated" tag in there for backwards compatibility.

ohh yea, and the link needs title attributes to be valid.... however i don't think his main goal is accessibility.

Bill Posters
10-07-2006, 08:53 AM
if your going to push accesability then why limit the 'jump' link to 'new' browsers.

it's no extra work to place a "deprecated" tag in there for backwards compatibility.
(Setting aside the fact that it, of course, is extra work, albeit not much…)

I wouldn't consider fragment anchors an issue of accessibility, but an issue of usability. The content can (or rather, should) be accessible with or without fragment links, regardless of which of the old or new methods you use to implement them.

If an author has marked up the rest of their document(s) in a way which somehow manages to knacker all other means of accessing the destination of that fragment identifier, then the site in question has far greater accessibility issues to worry about than whether or not to use named anchors.

Given that fragment anchors are a non-essential usability aid, it's fair game as to whether authors consider it worthwhile to add otherwise redundant markup (namely, named anchors) in order to bring obsolete UAs into the fold.

Edit: ohh yea, and the link needs title attributes to be valid
I trust you're not referring to validity in terms of the markup specifications.
It's not a requirement for 'validity' in WCAG1.0*, either.
So, in what way is the use of a title attribute needed for 'validity'?

* The closest the WCAG 1.0 comes to making it a requirement is Checkpoint 13.1 [P2] which recommends the use of the title attribute as an optional addition which may be used to convey further information beyond the essential destination info, which should be made clear in the link text itself, and/or in alt text, in the case of image links.
It's certainly not good practice to implement title text which simply reiterates a link's text content. Neither is it a good idea to rely on the title attribute to convey important information about a link's destination.