javascript - Strange behaviour with range.toString() -


I want to retrieve the selected text in an element using the range object provided by Mozilla's taste. .

So I do this:

  // Suppose I'm just using Firefox, and only one selection is var range = window.getSelection () . GetRangeAt (0); Var rangeText = range.toString ();  

This works fine when there is no new line in the html of the selected text, in other words, if I have the following HTML:

  & Lt; Div & gt; One. two. three. Four Five & Lt; / Div & gt;  

and I choose two three. Four , then everything is fine

On the other side, if I have

  & lt; Div & gt; One. two. three. Four Five. & Lt; / Div & gt;  

and I choose two three. Four As the first, new lines have been introduced in the result returned from the range. Two. , three. , and Four.

Obviously, when appearing in the browser, both Html fragments are the same, is there any way I can ensure that the same text is returned without new lines?

It should do this:

  range.toString (). Replace (/ \ s + / g, '') .replace (/ ^ \ s + | \ s + $ / g, '')  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -