Bookmarklet to show anchors and ids in a DOM Level 1 compliant browser

javascript:(function(){var atags,i,name,a,img,link ; anchs =
document.getElementsByTagName('*'); for(i=0; i<anchs.length; ++i) { a =
anchs[i] ; if (a.id || (a.tagName=="A" && a.name))
{img=document.createElement("img");
img.src="http://www.nimbustier.net/images/ancre.png" ;
img.style.border="none" ; img.alt="" ; if (a.id) {name = a.id;} else
{name = a.name;}; if (a.tagName!="A") { link =
document.createElement("a") ; } else {link=a; } ; link.href="#" + name ;
link.appendChild(img); if (a.tagName!="A") { a.appendChild(link);} ;
link.style.border = "1px solid black"; } } })();

It makes appear an anchor image after every tag with an id or an anchor
with a name, with a link to this anchor.

Inspired from http://www.la-grange.net/2002/03/21-bookmarklets#W3CSpec

Knonw Bugs:
- should check if the current <a name="foo"> has or not an href before
changing it, and if it does, create a separate link to the anchor

Works well with Mozilla 9.9, not tested with others.
-- 
Dominique Hazaël-Massieux - http://www.w3.org/People/Dom/
W3C's Webmaster
mailto:dom@w3.org

Received on Friday, 5 April 2002 10:00:46 UTC