|
|
Safari Javascript and focus()
|
|
|
|
Grizzled Veteran
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
Alright in Firefox when I use focus() on a textarea the caret moves right to the end of the text, however in safari it stays put.
On further testing it seems Safari doesn't even focus on the textarea at all, anyone got any ideas why this may be?
Thanks in advance
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
ok found out that safari doesn't seem to set the focus if you select the element via setting it to a variable using getElementById, forms[0].elementname however works but the caret still stays in the last position in the text area.
Anyone know how to move it to the end?
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status:
Offline
|
|
Yeah, Safari will put the carat back to where it was when the text area lost its focus.
Something like:
Code:
function focusToEnd() {
var to_focus = document.getElementById("id_of_textarea");
var to_collapse_to = to_focus.value.length;
to_focus.focus();
to_focus.setSelectionRange(to_collapse_to, to_collapse_to);
}
should work.
I should also note that calling focus() on the element referenced using getElementById worked fine for me... which version of safari are you using?
|
Just who are Britain? What do they? Who is them? And why?
Formerly Black Book
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
I'm using safari 2.0.3, cheers I thought something to do with selections might sort it out and I'll double check my getElementById method again to see if it was just a small inconsistency caused by caches
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|