W3C home > Mailing lists > Public > www-archive@w3.org > April 2002

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

From: Dominique HazaŽl-Massieux <dom@w3.org>
Date: 05 Apr 2002 17:00:44 +0200
To: www-archive@w3.org
Message-Id: <1018018845.7849.372.camel@nimbustier>
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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 7 November 2012 14:17:17 GMT