javascript - how to highlight words using start and end postiton -
i using below code , store start , end position of words want highlight words while refresh page.. how it.
function getselectioncharoffsetswithin(element) { var start = 0, end = 0; var sel, range, priorrange; if (typeof window.getselection != "undefined") { range = window.getselection().getrangeat(0); priorrange = range.clonerange(); priorrange.selectnodecontents(element[0]); priorrange.setend(range.startcontainer, range.startoffset); start = priorrange.tostring().trim().length; end = start + range.tostring().length; } else if (typeof document.selection != "undefined" && (sel = document.selection).type != "control") { range = sel.createrange(); priorrange = document.body.createtextrange(); priorrange.movetoelementtext(element); priorrange.setendpoint("endtostart", range); start = priorrange.text.length; end = start + range.text.length; } return { start: start, end: end }; }
Comments
Post a Comment