Focus Textarea With Caret After Text In Android Browser
I am currently writing a simple webapp to view tweets in the Android browser. I am using this code to focus the caret after the current text: var oldContent = document.tweetBox.tw
Solution 1:
Sounds like a browser bug. Try setting the caret position manually:
var textArea = document.tweetBox.tweet, oldContent = textArea.value;
textArea.value = oldContent + to;
textArea.focus();
textArea.selectionStart = textArea.selectionEnd = textArea.value.length;
Solution 2:
setCaret = function(obj,pos) {
// IE Supportif (document.selection) {
// Set focus on the element
obj.focus ();
// Create empty selection rangevar oSel = document.selection.createRange ();
// Move selection start and end to 0 position
oSel.moveStart ('character', -obj.value.length);
// Move selection start and end to desired position
oSel.moveStart ('character', pos);
}
//standard browserselseif (obj.selectionStart || obj.selectionStart == '0') {
obj.selectionStart = pos;
obj.selectionEnd = pos;
obj.focus ();
}
};
and setting to the right positions
setCaret(document.getElementById("area"),document.getElementById("area").value.length);
Post a Comment for "Focus Textarea With Caret After Text In Android Browser"