Set focus and carret position in textarea according to mouse position, as if user had clicked
Once a page with a textarea is loaded, I want some textarea to have the focus immediatly if the mouse cursor is inside that textarea. This is the easy part because a onmousehover handler can set the focus.
Now, how to I also set the position of the caret? I would like the caret to be where it would be if the user had clicked using the mouse to set the focus/caret.
The basic use case is :
- User clicks on a link and waits (mouse barely moves)
- A page i开发者_StackOverflow社区s delivered, it contains a big textarea only, full of text
- User types using keyboard
- Characters are inserted right below the mouse cursor
Today the user has to wait until the caret is visible (at the top left of the textarea) and then click to move the caret before typing.
Thanks!
精彩评论