- From: Dominique Hazaël-Massieux <dom@w3.org>
- Date: 05 Jul 2002 13:57:39 +0200
- To: www-archive@w3.org
Le ven 05/04/2002 à 17:00, Dominique Hazaël-Massieux a écrit : > 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. Updates: The bookmarklet doesn't work with versions of IE anterior to 6.x since document.getElementsByTagName('*') isn't interpreted correctly. For IE 6.x and following, due to a limitation of the length of a bookmark URI to 508 characters, you should use the shorten version below: javascript:(function(){var i,n,a,j,l;b=document.getElementsByTagName('*');for(i=0;i<b.length;++i){a=b[i];if(a.id||(a.tagName=="A"&&a.name)){j=document.createElement("img");j.src="http://www.nimbustier.net/images/ancre.png";j.style.border="none";j.alt="";if(a.id){n=a.id;}else{n=a.name;};if(a.tagName!="A"){l=document.createElement("a");}else{l=a;};l.href="#"+n;l.appendChild(j);if(a.tagName!="A"){a.appendChild(l);};l.style.border="1px solid black";}}})(); [sorry for the long line, but that it should be easier to paste it directly in your browser that way] Dom -- Dominique Hazaël-Massieux - http://www.w3.org/People/Dom/ W3C/INRIA mailto:dom@w3.org
Received on Friday, 5 July 2002 08:00:42 UTC