javascript - getting the absolute index of a DOM node -


i have piece of code returns me dom node.

<script>  function a(){  var userselection; if (window.getselection) {     userselection = window.getselection(); } else if (document.selection) { // should come last; opera!     userselection = document.selection.createrange(); }  var rangeobject = getrangeobject(userselection);  var node = rangeobject.startcontainer;  } function getrangeobject(selectionobject) {     if (selectionobject.getrangeat)         return selectionobject.getrangeat(0);     else { // safari!         var range = document.createrange();         range.setstart(selectionobject.anchornode,selectionobject.anchoroffset);         range.setend(selectionobject.focusnode,selectionobject.focusoffset);         return range;     } } </script> 

so need absolute index of var node, respect beggining of body tag. manage index in parent node. need absolute

the idea store index starting position of selected text in database , later retrieve them.

i trying build annotation tool, highlighting parts of text , leaving comment text , later when page being displayed need show annotated text.

function called when mouseup event on body fires


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -