javascript: create range from cursor position at time a to cursor position at time b -
i cursor position @ time a. cursor position @ time b. want make range cursor position @ time cursor position @ time b. time , b start , end of ctr-v (paste).
i cursor position - or rather range @ cursor position.
sel = window.getselection(); range_time_a = sel.getrangeat(0).collapse(true);
but, how use range_time_a , range_time_b create new range starts @ range_time_a , ends @ range_time_b?
i have seen code element cursor , offset within element. use setstart() , setend, seems there should easier way since i've got 2 ranges.
edit won't give you're looking for... complicated. initial suggestion of commonanscestorcontainer.innerhtml give (all html of closest parent container selection).
first, you're going want trigger code on eventhandler fires when user presses ctrl+c (discussion here: how detect ctrl+v, ctrl+c using javascript?).
if want text selected, that's done:
range = window.getselection().tostring();
you don't need check selection @ various times - need capture @ point user hits ctrl-c.
getselection not meant capturing html of selection. can capture text & remove text, move start/end of selection , bunch of other things described here, can't grab html.
big part of problem isn't part of stanfard spec (see this link). reason not consistent across browsers, or supported in ie7/8.
some non-standards based examples of how more info out of range selections can found here if need - get range's start , end offset's relative parent container
Comments
Post a Comment