views:

28

answers:

1

I understand that IE has a full-word selection feature, which people often want to turn off.

I want the opposite.

I want to automatically expand the selection to complete words in all browsers. Actually, for the moment, I don't really care about IE (but I will eventually).

Anyone know of a solution for this?

Thanks.

A: 

You may be able to do something in WebKit (and apparently Firefox 4) by using the modify method of the selection in conjunction with the mousemove event. It'll probably be quite tricky to get right though: you'll need to consider when it's appropriate to expand the selection.

Here's a very simple example of using the modify method:

<p>A paragraph with some nice text in it</p>

<script type="text/javascript">
    function expandSelection() {
        var sel;
        if (window.getSelection) {
            sel = window.getSelection();
            if (sel.modify) {
                sel.modify("extend", "forward", "word");
            }
        }
    }
</script>

<input type="button" onclick="expandSelection();" value="expand">
Tim Down
Thanks... this isn't as bad as I thought it would be. It will be tricky to get exactly what I'm after, even where it's supported, but this looks like the best I can do for now.
harpo