I want to get back the text that I select in an element using the Range object provided by Mozilla's flavour of javascript.
So I do this:
//assume that I'm only using Firefox, and there is just one selection
var range = window.getSelection().getRangeAt(0);
var rangeText = range.toString();
This works OK when the html of the selected text doesn't have any newlines In other words, if I have the following html:
<div>One. Two. Three. Four. Five.</div>
and I select Two. Three. Four., then everything is fine.
On the other hand, if I have
<div>
One.
Two.
Three.
Four.
Five.
</div>
and I select Two. Three. Four. as before, there are newlines introduced into the result returned from Range.toString(); the newlines are after Two., Three., and Four.
Obviously, when displayed in the browser, both html fragments are identical. Is there a way I can ensure that the same text is returned without newlines?