views:

32

answers:

1

The TextRange object of IE has expand function through which you can expand the text selection to complete the word or sentence. It only works for IE. More: http://www.webreference.com/js/column12/trmethods.html

It would be great if someone can help me and make it work cross-browser.

+1  A: 

WebKit and Firefox 4 have a modify() method of the Selection object that does a similar job to the expand() method of TextRanges.

Tim Down
Anything for Firefox 3? :(
Haris
Also, is it possible to complete words in both directions?
Haris
Nothing for Firefox 3, sorry. Re completing words in both directions: to be honest, I've barely used this method because of lack of support. What I do know is that `modify()` acts on the focus of the selection, which is the point in the document at which the user stopped selecting (which can be earlier in the document that where they started if they dragged backwards). You can also move the focus programmatically using `extend()`: https://developer.mozilla.org/en/DOM/Selection/extend
Tim Down