1

I'm developing simple form that generates piece of formatted text (you can take a look here). Idea is to simplify selection of created text. For desktop browsers following code with onсlick handler on div works great:

if (document.selection) {
    var range = document.body.createTextRange();
    range.moveToElementText(document.getElementById('template_text'));
    range.select();
}
else if (window.getSelection) {        
    var range = document.createRange();
    range.selectNode(document.getElementById('template_text'));
    window.getSelection().addRange(range);
}   

In mobile browsers (Android browser and Safari for iOS) this code just highlights div for a moment and nothing else. I don't want to create separate mobile version because it's only problem with the form.

Can text selection be simplified for mobile browsers in some way without affecting current functionality for desktop?

Thank you.

1 Answers1

0

According to answer from this thread you can go to http://detectmobilebrowsers.com/ and download the script which will give you a tool of detecting whether it's mobile or desktop browser is used by visitor. Then you just branch your code with simple if and arrange mobile and desktop behaviors of selecting text separately in this particular place

Community
  • 1
  • 1
Miroshko
  • 813
  • 6
  • 14