Search This Blog

Saturday, July 31, 2010

Looking for a better workaround to Chrome select on focus bug

Programmer Question

I have the same problem as the user in this question, which is due to this bug in Webkit. However, the workaround provided will not work for my app. Let me re-state the problem so that you don't have to go read another question:



I am trying to select all the text in a textarea when it gets focus. The following jQuery code works in IE/FF/Opera:



$('#out').focus(function(){
$('#out').select();
});


However, in Chrome/Safari the text is selected--very briefly--but then the mouseUp event is fired and the text is deselected. The following workaround is offered in the above links:



$('#out').mouseup(function(e){
e.preventDefault();
});


However, this workaround is no good for me. I want to select all text only when the user gives the textarea focus. He must then be able to select only part of the text if he chooses. Can anyone think of a workaround that still meets this requirement?



Find the answer here

No comments:

Post a Comment

Related Posts with Thumbnails