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
Post a Comment