
Originally Posted by
Agrajag
for the sake of accessibility, the script first hides all the divs, then shows one of them. this way, if a visitor does not have javascript enabled, the divs will show normally down the page. i've also included named links for anyone without javascript.
Sounds good so far.
what i want to know is, can i use the #linkname on the end of a url to automaticall switch to the right div when the page loads?
You certainly could parse out the fragment identifier and, if present, use that rather than the default.
Code:
function getFragment(uri) {
var i = uri.indexOf('#');
if (i != -1) return uri.substring(i + 1);
return null;
}
So, for example, you might write something like:
Code:
if (document.getElementById) {
var id, element;
/* If the URI contained a fragment identifier... */
if (!(id = getFragment(document.URI))
/* ...and that fragment identified an element within the
* document, use it to reveal that element.
*/
|| !(element = document.getElementById(id))) {
/* Otherwise, assume the default. */
element = document.getElementById('defaultId');
}
/* If an element was obtained and it has a style object... */
if (element && element.style)
/* ...show that element. */
element.style.display = '';
}
Hope that helps.

Originally Posted by
djr33
the # is more for anchors (like... snapping to the bottom of the page). Not sure if there're more uses, though.
The purpose of fragment identifiers in URIs is defined by the URI scheme and the context of its use. In HTML, it provides a means for linking to destination anchors (<a name="..."> or <... id="...">). Its use varies elsewhere.
Mike
Bookmarks