I'm trying to create a selection that goes from right to left in the text, but it seems the DOM Range API doesn't let me do that. (I don't see anything about this in the spec - not that I read it closely - but all implementations seem to agree on not supporting it.)
For example, given a very minimal document:
data:text/html,<div> this is a test </div>
I can use this script to enable editing and create a normal selection (for example from a bookmarklet, but line wrapping added for clarity):
javascript:document.designMode='on';
var r=document.createRange(),d=document.getElementsByTagName('div')[0];
r.setStart(d.firstChild, 3);
r.setEnd(d.firstChild, 7);
window.getSelection().addRange(r); void(0);
However, if I swap 3 and 7 no selection is created.
Does anyone know a way to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…