Why a dropdown list? Why not use an (un)ordered list in which the list items are good old hypertext links?
Also, don’t the 8 PHP search&replace;‘s make the script slow?
Using XML/XSLT here seems like a wonderful idea to me. An XML sitemap could easily be transformed into a series of LINK elements, as well as a normal list.
anon, yes, both valid points. I chose the dropdownnot to waste much screen estate. The regexp are not much of performance issue, after all, this is executed on the server.
As for PHP, again, this is a fallback, if you want to use any other technique, be my guest.
If you can use includes, you can store your link data in PHP in a database or associative array and automatically populate prev and next, too, by reading the current page name.
I used this technique in my unobtrusive Javascript course in case you want to see an example. I wanted users to go through it page by page, but have a chance to shortcut, should they come back later:
http://www.onlinetools.org/articles/unobtrusivejavascript/
No need for this script if you use Opera or Mozilla! They display the navigation bar for you to click on. Great idea though – you could have something big here. How about improving it way beyond what the aforementioned browsers can do?
Copy & paste the code below to embed this comment.
Darren
Drop down nav.
If you have 30+ pages on a website then a drop down list can be a bit hard to wade through. As navigation I don’t like drop down menu’s that much. They can be powerful in some instances though such as a links page. I use several drop downs on my own links page which loads pages into a frame. Quite handy there but not too useful for nav otherwise.
If you are going for a list all approach I think CSS/dhtml techniques are better and more usable I believe especially with sub menus.
Drop downs might be handy if you are using sub index pages where not all links are 1 click away but a simple site map page can do the same job whilst saving a lot of code on every page.
true, and your point is? Again: This is not to replace a navigation of a web site, we talk about linked documents here, which have a common theme, much like tutorials and online books. LINK is not a navigation replacement, it is above the site navigation, a structural meta navigation.
Copy & paste the code below to embed this comment.
D K
if I have to type out all that js to render a two option dropdown it doesn’t seem very productive. I still can’t exactly tell where the ‘dynamic’ even comes into play after reading it 3x over ? anyone care to explain ?
How i’ve handled this problem is server-side using php. I read the directory I specify in and grab all files with a .html and dynamically generate a dropdown box on a loop using the list of contents from the dir scan. Now that is dynamic [and less lines of code than this JS in the article]…. and server side which leaves no chance of the user being able to interfere by turning a browser preference off.
Well, kudos to you, you found yet another way to do the same.
I also take in your point about dynamic, as it is a misnomer in this case. The dynamic bit is the generation of the dropdown from data in the document, data that otherwise would only be there for clients that support LINK. IE for example does not use the link data we put in for anything, which means a lot of developers don’t even bother adding this data.
Dynamic in your sense means that the link data and the navigation gets generated for each document server side by reading all documents and also setting prev and next, which is exactly what you should do and is a great idea. This article, above all, was meant to raise awareness for the LINK element. Some of the original explanations and intensions got lost in the editing process though.
However, your point about “all these lines of code” you need to “type in”, is a meek one, as all you need to do is to call the script in the zip via ONE script tag. The script can also be done in 20 lines less, but is less legible and worse as a code example then.
Copy & paste the code below to embed this comment.
pTer
Nice use of the LINK tag. I wish we could use more standard HTML elements than just the
“strangeset” IE implements. Maybe as IE becomes less used. I’ve got my Mom using Mozilla. It starts at home. Good job Chris.
Copy & paste the code below to embed this comment.
cawb
Peter-Paul Koch has used this technique for some time on his own site to create a few unobtrusive links at the bottom of each page. He also uses his sitemap as the navigation for his entire site (in a frame not an SSI) using javascript to make it into a dhtml menu. His work should probably have been credited here, and is likely better written.
Interesting, didn’t know that. I just went through his script and saw what you mean:
var y = document.getElementsByTagName(‘link’);
var links = ‘’;
for (var i=0;i<y.length;i++)
{
if (y.getAttribute(‘rel’) == ‘stylesheet’) continue;
links += ‘ ’ + y.getAttribute(‘rel’) + ‘’;
}
links += ‘
‘;
links += ‘home’;
links += ‘sitemap’;
links += ‘contact’;
links += ‘copyright’;
However, I was not aware of it and unless you read the “making of quirksmode” article on the site you wouldn’t be either. So let’s be a bit more careful assuming that some ideas were taken from somewhere else, shall we?
Personally I am not a big fan of writing out HTML without generating it via DOM, but that is just me.
Copy & paste the code below to embed this comment.
manu
I have a website that must be accessible for non Javascript users, yet I want Javascript users to navigate the site usings a drop down menu (with Javascript redirection).
With this technique non-Javascript users do not have to see the (then useless) menu and only see the textual links I’ve placed in a noscript tag.
We are talking about two different things here. This technique is there to show accessibility enhancing LINK info for IE. A Javascript Navigation can be made accessible by simply making it non-dependent on Javascript but enhance it by it.
It works in IE5, you can test it by downloading the standalone IE5 versions out there on the web.
http://www.skyzyx.com/archives/000094.php
You can make a dropdown with javascript redirection accessible by applying the javascript onsubmit rather than onchange on the select. All you need is a Javascript fallback on the server side.
http://www.evolt.org/forms_javascript/
1. some good ideas on using existing markup in other ways
2. every idea at ala (and elsewhere) is to be built upon and explored (it still humors me to see the ‘I already did that’ post, or ’ I can do one better’… …that’s great…
but, man, sometimes these discussions make you not wanna write another article, huh?
so, nothing but thanks for your time and effort trying to help people.
Dante, as pointed out by Chris, using onsubmit on a button rather than onchange on the drop-down menu is the accessible option. The reason for this is the browser will only go to get a page when the user confirms they want that to happen.
If the user had limited mobility with a pointing device they may accidentally change the drop-down menu to an option they actually do not want. Or, maybe the user is negotiating the drop-down menu using the keyboard: they would use arrow keys to select the option they want and would then tab to the submit button.
Cheers, that was the reason. It is negotiable though if users who rely on keyboard navigation don’t actually know that a dropdown onselect is accessible when you pressl alt+arrow down first to expand it and then choose by using arrow up and down and submitting with enter.
Lynx, and maybe other text browsers, display the <link> links at the beginning of the document. If you include too many, it takes a long time to tab past them all to get to any links in the content.
A workaround is to make the first <link> point to an anchor at the beginning of the content, effectively skipping the <link> links.
My site uses next, prev, up and start “special” links extensively, with a “control bar” in the header to allow those without Opera/Mozilla to access them.
Copy & paste the code below to embed this comment.
Chris
What is a BFU? And let’s not forget that a lot of alternative User agents do support LINK to start with, and the dropdown only appears when DOM is available. This means that the chances of a User agent creating the dropdown not being able to render it is very slim.
Copy & paste the code below to embed this comment.
lunchmeat
i think this is a really cool idea, but the main problem i have with it isn’t the HTML bloating or the non-javascript browsers and whatnot. My question is: don’t browsers preload anything within a link attribute? anything in a link tag will be preloaded because of the html DOM. if there’s a way to turn off that option in the HTML somehow, that would make this much more worthwhile for me. i personally wouldn’t want to link a multitude of documents only to make my visitors wait for them to preload.
that’s really my one question, unless there’s a way to link to a document that contains all the links, a table of contents or index or sorts…i dunno, my mind is running away with the possibilities.
(i don’t know if anyone pays attention to these threads anymore, since the article’s a bit old…but there seems to be a tiny issue with spam up there.)
Copy & paste the code below to embed this comment.
rehfeld
some browsers may preload certain types of links, but unless the link is something like a stylesheet or a favicon etc… it will not delay the display of the page. but to my knowledge, most will not be preloaded at all.
i beleive in all newer gecko based browsers you can make the browser preload/prefetch by using:
<link rel=“prefetch” href=”/foo.html” />
again, this will not delay the display of the current page. it will be processed after the current page is done displaying.
Eric Meyer’s standards-based slide show (11-12/04), like Christian’s drop-down (5/04) splits one page into many “slides” and automatically generates a dropdown menu by which to navigate from one “slide” to another.
As you might expect, the differences between Eric’s and Christian’s ideas are as interesting as the similarities.
38 Reader Comments
Back to the Articleamon-re
Why a dropdown list? Why not use an (un)ordered list in which the list items are good old hypertext links?
Also, don’t the 8 PHP search&replace;‘s make the script slow?
Using XML/XSLT here seems like a wonderful idea to me. An XML sitemap could easily be transformed into a series of LINK elements, as well as a normal list.
Chris
anon, yes, both valid points. I chose the dropdownnot to waste much screen estate. The regexp are not much of performance issue, after all, this is executed on the server.
As for PHP, again, this is a fallback, if you want to use any other technique, be my guest.
If you can use includes, you can store your link data in PHP in a database or associative array and automatically populate prev and next, too, by reading the current page name.
I used this technique in my unobtrusive Javascript course in case you want to see an example. I wanted users to go through it page by page, but have a chance to shortcut, should they come back later:
http://www.onlinetools.org/articles/unobtrusivejavascript/
Chris Hester
No need for this script if you use Opera or Mozilla! They display the navigation bar for you to click on. Great idea though – you could have something big here. How about improving it way beyond what the aforementioned browsers can do?
Darren
Drop down nav.
If you have 30+ pages on a website then a drop down list can be a bit hard to wade through. As navigation I don’t like drop down menu’s that much. They can be powerful in some instances though such as a links page. I use several drop downs on my own links page which loads pages into a frame. Quite handy there but not too useful for nav otherwise.
If you are going for a list all approach I think CSS/dhtml techniques are better and more usable I believe especially with sub menus.
Drop downs might be handy if you are using sub index pages where not all links are 1 click away but a simple site map page can do the same job whilst saving a lot of code on every page.
Chris
true, and your point is? Again: This is not to replace a navigation of a web site, we talk about linked documents here, which have a common theme, much like tutorials and online books. LINK is not a navigation replacement, it is above the site navigation, a structural meta navigation.
D K
if I have to type out all that js to render a two option dropdown it doesn’t seem very productive. I still can’t exactly tell where the ‘dynamic’ even comes into play after reading it 3x over ? anyone care to explain ?
How i’ve handled this problem is server-side using php. I read the directory I specify in and grab all files with a .html and dynamically generate a dropdown box on a loop using the list of contents from the dir scan. Now that is dynamic [and less lines of code than this JS in the article]…. and server side which leaves no chance of the user being able to interfere by turning a browser preference off.
D K
I forgot to say that I see how it could be more useful from an accesibility standpoint but I don’t see the dynamic part ?
Chris
Well, kudos to you, you found yet another way to do the same.
I also take in your point about dynamic, as it is a misnomer in this case. The dynamic bit is the generation of the dropdown from data in the document, data that otherwise would only be there for clients that support LINK. IE for example does not use the link data we put in for anything, which means a lot of developers don’t even bother adding this data.
Dynamic in your sense means that the link data and the navigation gets generated for each document server side by reading all documents and also setting prev and next, which is exactly what you should do and is a great idea. This article, above all, was meant to raise awareness for the LINK element. Some of the original explanations and intensions got lost in the editing process though.
However, your point about “all these lines of code” you need to “type in”, is a meek one, as all you need to do is to call the script in the zip via ONE script tag. The script can also be done in 20 lines less, but is less legible and worse as a code example then.
pTer
Nice use of the LINK tag. I wish we could use more standard HTML elements than just the
“strangeset” IE implements. Maybe as IE becomes less used. I’ve got my Mom using Mozilla. It starts at home. Good job Chris.
cawb
Peter-Paul Koch has used this technique for some time on his own site to create a few unobtrusive links at the bottom of each page. He also uses his sitemap as the navigation for his entire site (in a frame not an SSI) using javascript to make it into a dhtml menu. His work should probably have been credited here, and is likely better written.
Chris
Interesting, didn’t know that. I just went through his script and saw what you mean:
var y = document.getElementsByTagName(‘link’);
var links = ‘’;
for (var i=0;i<y.length;i++)
{
if (y.getAttribute(‘rel’) == ‘stylesheet’) continue;
links += ‘ ’ + y.getAttribute(‘rel’) + ‘’;
}
links += ‘
‘;
links += ‘home’;
links += ‘sitemap’;
links += ‘contact’;
links += ‘copyright’;
However, I was not aware of it and unless you read the “making of quirksmode” article on the site you wouldn’t be either. So let’s be a bit more careful assuming that some ideas were taken from somewhere else, shall we?
Personally I am not a big fan of writing out HTML without generating it via DOM, but that is just me.
manu
I have a website that must be accessible for non Javascript users, yet I want Javascript users to navigate the site usings a drop down menu (with Javascript redirection).
With this technique non-Javascript users do not have to see the (then useless) menu and only see the textual links I’ve placed in a noscript tag.
My concern: does it work in IE5 (DOM support) ?
Chris
We are talking about two different things here. This technique is there to show accessibility enhancing LINK info for IE. A Javascript Navigation can be made accessible by simply making it non-dependent on Javascript but enhance it by it.
It works in IE5, you can test it by downloading the standalone IE5 versions out there on the web.
http://www.skyzyx.com/archives/000094.php
You can make a dropdown with javascript redirection accessible by applying the javascript onsubmit rather than onchange on the select. All you need is a Javascript fallback on the server side.
http://www.evolt.org/forms_javascript/
Dante
I’m posting from Northern Ireland right now so I won’t say too much…
Opera 7 already has this feature. But maybe you should use onchange for the form instead of a button.
Chris
And yes, as stated “Some browsers use its data to show a toolbar — alas, the son of the giant of Redmond does not, and his followers are legion.”
zack
1. some good ideas on using existing markup in other ways
2. every idea at ala (and elsewhere) is to be built upon and explored (it still humors me to see the ‘I already did that’ post, or ’ I can do one better’… …that’s great…
but, man, sometimes these discussions make you not wanna write another article, huh?
so, nothing but thanks for your time and effort trying to help people.
[undisclosed location]
peace
z
Lewis
Dante, as pointed out by Chris, using onsubmit on a button rather than onchange on the drop-down menu is the accessible option. The reason for this is the browser will only go to get a page when the user confirms they want that to happen.
If the user had limited mobility with a pointing device they may accidentally change the drop-down menu to an option they actually do not want. Or, maybe the user is negotiating the drop-down menu using the keyboard: they would use arrow keys to select the option they want and would then tab to the submit button.
:-)
Chris
Cheers, that was the reason. It is negotiable though if users who rely on keyboard navigation don’t actually know that a dropdown onselect is accessible when you pressl alt+arrow down first to expand it and then choose by using arrow up and down and submitting with enter.
Mark
Lynx, and maybe other text browsers, display the <link> links at the beginning of the document. If you include too many, it takes a long time to tab past them all to get to any links in the content.
A workaround is to make the first <link> point to an anchor at the beginning of the content, effectively skipping the <link> links.
My site uses next, prev, up and start “special” links extensively, with a “control bar” in the header to allow those without Opera/Mozilla to access them.
PNDesign
This is nice, but one problem is, that much BFUs don’t use drop-down list..or it is not effective way of navigation.
Chris
What is a BFU? And let’s not forget that a lot of alternative User agents do support LINK to start with, and the dropdown only appears when DOM is available. This means that the chances of a User agent creating the dropdown not being able to render it is very slim.
Rolex Replica
Opera 7 already has this feature…..
diseño web
congratulations for the article.
lunchmeat
i think this is a really cool idea, but the main problem i have with it isn’t the HTML bloating or the non-javascript browsers and whatnot. My question is: don’t browsers preload anything within a link attribute? anything in a link tag will be preloaded because of the html DOM. if there’s a way to turn off that option in the HTML somehow, that would make this much more worthwhile for me. i personally wouldn’t want to link a multitude of documents only to make my visitors wait for them to preload.
that’s really my one question, unless there’s a way to link to a document that contains all the links, a table of contents or index or sorts…i dunno, my mind is running away with the possibilities.
(i don’t know if anyone pays attention to these threads anymore, since the article’s a bit old…but there seems to be a tiny issue with spam up there.)
thanks.
rehfeld
some browsers may preload certain types of links, but unless the link is something like a stylesheet or a favicon etc… it will not delay the display of the page. but to my knowledge, most will not be preloaded at all.
i beleive in all newer gecko based browsers you can make the browser preload/prefetch by using:
<link rel=“prefetch” href=”/foo.html” />
again, this will not delay the display of the current page. it will be processed after the current page is done displaying.
heres an nice link
http://www.mozilla.org/projects/netlib/Link_Prefetching_FAQ.html
Neal Krouse
I see nothing, and I get several error messages in my Internet Explorer for Mac.
lunchmeat
thanks, very helpful. i might use that with my small site, which is only a few pages really.
apartness
Creatively related (but developed independently):
http://meyerweb.com/eric/tools/s5/
Eric Meyer’s standards-based slide show (11-12/04), like Christian’s drop-down (5/04) splits one page into many “slides” and automatically generates a dropdown menu by which to navigate from one “slide” to another.
As you might expect, the differences between Eric’s and Christian’s ideas are as interesting as the similarities.