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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -