Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting text on focus using jQuery not working in iPhone iPad Browsers [duplicate]

We are developing Web-App for Mobile browsers, we would like text of any input box to get selected whenever input-box get focus. Below answer fixes the issue for Desktop chrome/safari browser. Below solution works fine on Android browser, but not on iPhone/iPad browsers, any solution..

$("#souper_fancy").focus(function() { $(this).select() });

$("#souper_fancy").mouseup(function(e){
        e.preventDefault();
});

Ref:-

Selecting text on focus using jQuery not working in Safari and Chrome

like image 676
Anand Avatar asked Mar 29 '12 11:03

Anand


2 Answers

Answer found here don't know how to mark this question as duplicate. Programmatically selecting text in an input field on iOS devices (mobile Safari)

My fix look like this:-

<script type="text/javascript">
           $('div,data-role=page').live('pageshow', function (event) {
               jQuery.validator.unobtrusive.parse(".ui-page-active form");
               $("input[type='text'], textarea, input[type='password'], input[type='number']").live('mouseup', function (e) { e.preventDefault(); });
               $("input[type='text'], textarea, input[type='password'], input[type='number']").live('focus', function () {this.setSelectionRange(0, 9999); });             
           });       
    </script>
like image 154
Anand Avatar answered Sep 23 '22 05:09

Anand


Maybe try this:

vmouseup
Normalized event for handling touchend or mouseup events

  • http://jquerymobile.com/demos/1.1.0-rc.1/docs/api/events.html

JS:

$("#souper_fancy").focus(function() { 
    $(this).select();
});

$("#souper_fancy").vmouseup(function(e){
    e.preventDefault();
});
like image 45
Phill Pafford Avatar answered Sep 24 '22 05:09

Phill Pafford