- From: Jim Ley <jim@jibbering.com>
- Date: Fri, 5 Apr 2002 15:55:33 -0000
- To: (wrong string) ël-Massieux" <dom@w3.org>
- Cc: <www-archive@w3.org>
"Dominique Hazaël-Massieux" <dom@w3.org> > It makes appear an anchor image after every tag with an id or an anchor > with a name, with a link to this anchor. I use: javascript: document.body.onmousedown=function(e) { e= e || event; var x=e.pageX || e.offsetX; var y=e.pageY || e.offsetY; var neardif=100000; var curmatch=-1; da=document.anchors; if (da) for (var i=0;i<da.length;i++) {; if (Compare(da[i],x,y)<neardif) {; curmatch=i; neardif=Compare(da[i],x,y); }} { if (curmatch!=-1) {window.clipboardData.setData('text',location.href+"#"+(da[curmatch].id ? da[curmatch].id : da[curmatch].name))}}}; Compare=function(el,x,y) {p1=GetPos(el);ydif=y-p1[1];if (ydif<0) return 10000; return ydif }; GetPos=function(el) { var _x=el.offsetLeft; var _y=el.offsetTop; while (el.offsetParent || el.offsetNode) { el=el.offsetParent || el.offsetNode; _x+=el.offsetLeft; _y+=el.offsetTop; }; return new Array(_x,_y); };void 0 In IE, for something similar, it creates a onmousedown handler, so that when you click anywhere on the page, it finds the nearest preceding anchor, and places a link to that anchor in the clipboard. Other than the clipboard part it works in Mozilla too. changing: window.clipboardData.setData('text',location.href+"#"+(da[curmatch].id ? da[curmatch].id : da[curmatch].name)) to writing out the link the page is what you need for mozilla. It only does anchors, not any element with an id. Jim.
Received on Friday, 5 April 2002 11:32:55 UTC